Strange behaviour, program segfaults

André Reffhaug areffhaug at gmail.com
Mon Apr 10 23:21:42 PDT 2006


On 4/11/06, Peter Johnson <peter at tortall.net> wrote:
> On Mon, 10 Apr 2006, André Reffhaug wrote:
>
> > On 4/10/06, Michael Urman <mu at tortall.net> wrote:
> >> Just as a data point, since I don't know gas the way Peter does. I get
> >> the following errors when I run it with your code:
> >>
> >> % ./yasm -p gas -f elf gastest.asm
> >> % ld gastest.o -o gastest
> >> ld: gastest: warning: allocated section `.text' not in segment
> >> % ./gastest
> >> zsh: exec format error: ./gastest
> >>
> >> When I crossreferenced for the usage in our test cases, it uses ".text"
> >> instead of ".section .text" so I tried that and it seems to execute
> >> properly:
> >>
> >> % ./gastest
> >> zsh: exit 33    ./gastest
> >>
> >> Peter will have to sort out whether this behavior is by design or by
> >> accident. Since you say it works with as, I'm going to guess it's a
> >> design oversight. And a great thing to catch before the final release of
> >> 0.5.0! :)
> >
> > This is quite interesting. First off, my ld doesn't give me the
> > warning you get for the .section .text-line at all. It just links in
> > silence. (ld version 2.16.1).
> >
> > And second, when removing ".section" from the sourcecode, the compiled
> > version still segfaults on my system. Yasm is latest release, rc2.
> >
> > Very strange, and perhaps import as to a new release.
>
> I'll take a look at changing the .section behavior (why it doesn't work is
> that no section flags have been specified; yasm defaults to a very
> restrictive non-code set of flags, whereas GAS either guesses based on
> section name or defaults to code).
>
> I see the same behavior Michael sees, however: if ".section .text" is
> replaced with ".text", the code in your original message runs just fine
> after being assembled with yasm and linked.  Is that the entire test
> you're running or is there some additional code that's also in your local
> version?  Linking with any other code?

I am just compiling the code given, no other linking or additional code:

anakron at demian:~/kode/asm/test$ cat test.s
.text

.globl _start

_start:
       pushl $3
       pushl $2
       call power
       addl $8, %esp
       pushl %eax

       pushl $2
       pushl $5
       call power
       addl $8, %esp

       popl %ebx
       addl %eax, %ebx

       movl $1, %eax
       int $0x80

.type power, @function
power:
       pushl %ebp
       movl %esp, %ebp
       subl $4, %esp
       movl 8(%ebp), %ebx
       movl 12(%ebp), %ecx

       movl %ebx, -4(%ebp)

power_loop_start:
       cmpl $1, %ecx
       je end_power
       movl -4(%ebp), %eax
       imull %ebx, %eax
       movl %eax, -4(%ebp)

       decl %ecx
       jmp power_loop_start

end_power:
       movl -4(%ebp), %eax
       movl %ebp, %esp
       popl %ebp
       ret

anakron at demian:~/kode/asm/test$ yasm -p gas -f elf test.s -o test.o
anakron at demian:~/kode/asm/test$ ld test.o -o test
anakron at demian:~/kode/asm/test$ ./test
Segmentation fault
anakron at demian:~/kode/asm/test$


Regards,
André


More information about the yasm-devel mailing list