Re: Issue linking 32-bit GAS assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Wed, Oct 17, 2018 at 11:07:02PM +0200, Maarten de Vries via arch-general wrote:
> Why not let gcc take care of what compiler/assembler and linker to invoke
> with which precise flags:
> 
> $ gcc -m32 -o foo filename.s
> $ ./foo # great success!
> 
> It will probably link to libc without you even asking for it. And if that
> works and you really want to know what linker flags you need, you can add -v
> to make gcc spam you about it.
> 

GCC will handle some files, but not others.  In this case, I get
garbage output then a segfault/core dump.

Using -nostdlib and -static also fail to build, but I have had success
with just using <gcc -m32 -nostartfiles -o file file.s>

I would, however, like to know how to use as/ld on Arch, as it is my
main OS.



> 
> -- Maarten
> 
> (Sent off-list by accident before, sending to the list now.)
> 
> 
> On 10/17/18 9:36 PM, Dutch Ingraham wrote:
> > Hi all:
> > 
> > I'm having a problem linking 32-bit GAS assembly code that references external
> > C libraries on an up-to-date 64-bit Arch installation.
> > 
> > I have enabled the 32-bit repositories and installed the multilib-devel group
> > and lib32-glibc. I have updated the library cache with ldconfig and rebooted.
> > 
> > The command to assemble is: <as --32 -o filename.o filename.s>.  Assembly
> > succeeds.
> > 
> > However, when linking using the command
> > <ld -melf_i386 --dynamic-linker /lib32/ld-linux.so.2 -lc -o filename filename.o>
> > 
> > the command fails with:
> > 	ld: skipping incompatible /usr/lib/libc.so when searching for -lc
> > 	ld: skipping incompatible /usr/lib/libc.a when searching for -lc
> > 	ld: cannot find -lc
> > 
> > Note this linker command (or a hierarchy-appropriate one) seems standard, and
> > succeeds on a 64-bit Debian OS.
> > 
> > There is a fairly recent Forum question (but pre-dating the discontinuance of
> > i686 support) regarding the same issue at
> > https://bbs.archlinux.org/viewtopic.php?id=229235 which indicates the command
> > should be:
> > 
> > <ld -melf_i386 -shared -L /usr/lib32 -dynamic-linker /lib/ld-linux.so.2 -o \
> > filename filename.o -lc>
> > 
> > This command succeeds, insofar as the linker returns an exit code of 0. However,
> > running the program (and all other similar programs) fails with "Illegal
> > instruction (core dumped)." Assembling with debugging symbols and running a
> > backtrace didn't enlighten me.
> > 
> > Note that changing /lib/ld-linux to /usr/lib32/ld-linux in the command immediately
> > above produces the same result, as confirmed by the output of <ldconfig -p>
> > 
> > Anyone see something I've missed of have any suggestions?  Thanks.
> > 
> > 
> > -----------
> > 
> > Here is some simple code to test with:
> > 
> > 
> > # paramtest2.s - Listing system environment variables
> > .section .data
> > output:
> >     .asciz "%s\n"
> > .section .text
> > .globl _start
> > _start:
> >     movl %esp, %ebp
> >     addl $12, %ebp
> > loop1:
> >     cmpl $0, (%ebp)
> >     je endit
> >     pushl (%ebp)
> >     pushl $output
> >     call printf
> >     addl $12, %esp
> >     addl $4, %ebp
> >     loop loop1
> > endit:
> >     pushl $0
> >     call exit



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux