On Tue, Apr 5, 2011 at 11:27 AM, Valery Reznic <[email protected]>wrote:
> > Create programs using gcc -m32 is fine. > But I use ld command not to create the program, but to create object file > > While both > ld -m elf_i386 file1.o file2.o -o output.o > and > gcc -m32 file1.o file2.o -o output.o > > create EXECUTABLE file (despite .o extension) > > I use > ld -r file1.o file2.o -o output.o # Note -r > > that create "partially linked object file" > AFAIK, you can do everything you can do with ld via a "compiler driver". You only need to make sure that a) you pass the right options to the linker (using -Wl) and b) gcc does not attempt to do too much (e.g., pass default startfiles and standard libraries to ld - it may fail if you do it not for the actual architecture as you attempt to do). E.g., $ cat > file1.c static int foo = 1; $ cat > file2.c static int bar = 2; $ gcc -m32 -nostartfiles -nostdlib -Wl,--relocatable file1.c file2.c -o file.o $ file file.o file.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped This _should_ be equivalent to what you are doing, the only arguable advantage is that gcc compiles and links in one go. Note that _maybe_ (I have not tested it) gcc can do what you want in yet another way - you can combine several compilation units into one object at compile time using the -combine option (only works for C code!): $ gcc -m32 -c -combine file1.c file2.c -o file.o $ file file.o file.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped -- Oleg Goldshmidt | [email protected]
_______________________________________________ Linux-il mailing list [email protected] http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
