On 9/28/10, Anton Shterenlikht <me...@bristol.ac.uk> wrote:
> I'm trying to learn the very basics of the
> compile - assemble - link process on FreeBSD.
> Please don't shoot me.
>
> I've this c code:
>
> % cat tmp.c
> int main() {
>         int a;
>         int b;
>         int c;
>
>         a = 2;
>         b = 3;
>
>         c=a*b;
> }
>
> which I compile into assembly language:
>
> % gcc -v
> Using built-in specs.
> Target: ia64-undermydesk-freebsd
> Configured with: FreeBSD/ia64 system compiler
> Thread model: posix
> gcc version 4.2.1 20070719  [FreeBSD]
>
> % gcc -S tmp.c
>
> I then assemble the object file:
>
> % gcc -o tmp.o -c tmp.s
> % file tmp.o
> tmp.o: ELF 64-bit LSB relocatable, IA-64, version 1 (FreeBSD), not stripped
>
> Then I try to link the object file into
> an executable:
>
> % ld tmp.o

You are missing something in above command.
> ld: warning: cannot find entry symbol _start; defaulting to 20000000000000f0
>
> Finally, when I try to run the executable,
> I get segfault:
>
> % ./a.out
> Segmentation fault (core dumped)
>
>
> Looking at the asm listing, there is indeed no
> _start symbol:
>
>
>       .file   "tmp.c"
>       .pred.safe_across_calls p1-p5,p16-p63
>       .text
>       .align 16
>       .global main#
>       .proc main#
> main:
>       .prologue 2, 2
>       .vframe r2
>       mov r2 = r12
>       .body
>       ;;
>       adds r15 = 8, r2
>       addl r14 = 2, r0
>       ;;
>       st4 [r15] = r14
>       adds r15 = 4, r2
>       addl r14 = 3, r0
>       ;;
>       st4 [r15] = r14
>       adds r14 = 8, r2
>       adds r15 = 4, r2
>       ;;
>       ld4 r16 = [r14]
>       ld4 r14 = [r15]
>       ;;
>       setf.sig f6 = r16
>       setf.sig f7 = r14
>       ;;
>       xmpy.l f6 = f6, f7
>       ;;
>       getf.sig r14 = f6
>       ;;
>       st4 [r2] = r14
>       .restore sp
>       mov r12 = r2
>       br.ret.sptk.many b0
>       ;;
>       .endp main#
>       .ident  "GCC: (GNU) 4.2.1 20070719  [FreeBSD]"
>
>
> What am I missing?
>
> I'm happy to be referred to FM.
>
> many thanks
> anton
>
> --
> Anton Shterenlikht
> Room 2.6, Queen's Building
> Mech Eng Dept
> Bristol University
> University Walk, Bristol BS8 1TR, UK
> Tel: +44 (0)117 331 5944
> Fax: +44 (0)117 929 4423
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
>
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to