[hjl@gnu-6 pr19118]$ make clean rm -f *.o *.so *.a [hjl@gnu-6 pr19118]$ cat x.s .text .type _start,"function" .global _start _start: .byte 0 [hjl@gnu-6 pr19118]$ make ./as --32 -o x.o x.s ./ld -m elf_foobar -o x x.o [hjl@gnu-6 pr19118]$ ld -m elf_foobar -o x x.o ld: unrecognised emulation mode: elf_foobar Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om [hjl@gnu-6 pr19118]$
[hjl@gnu-6 pr19119]$ cat x.s .text .type _start,"function" .global _start _start: ret [hjl@gnu-6 pr19119]$ make ./as --32 -o x.o x.s ./ld -m elf_iamcu -o x x.o [hjl@gnu-6 pr19119]$ file x x: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped [hjl@gnu-6 pr19119]$ ld -m elf_iamcu -o x x.o ld: i386 architecture of input file `x.o' is incompatible with iamcu output [hjl@gnu-6 pr19119]$ Gold simply ignores -m elf_iamcu.
Yes, gold uses the target of the first object file; only if there are no object files does it use the -m option (note that the option is marked "obsolete"). -cary On Wed, Oct 14, 2015 at 7:39 AM, hjl.tools at gmail dot com <sourceware-bugzilla@sourceware.org> wrote: > https://sourceware.org/bugzilla/show_bug.cgi?id=19119 > > --- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> --- > [hjl@gnu-6 pr19119]$ cat x.s > .text > .type _start,"function" > .global _start > _start: > ret > [hjl@gnu-6 pr19119]$ make > ./as --32 -o x.o x.s > ./ld -m elf_iamcu -o x x.o > [hjl@gnu-6 pr19119]$ file x > x: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, > not stripped > [hjl@gnu-6 pr19119]$ ld -m elf_iamcu -o x x.o > ld: i386 architecture of input file `x.o' is incompatible with iamcu output > [hjl@gnu-6 pr19119]$ > > Gold simply ignores -m elf_iamcu. > > -- > You are receiving this mail because: > You are the assignee for the bug.
(In reply to Cary Coutant from comment #2) > Yes, gold uses the target of the first object file; only if there are > no object files does it use the -m option (note that the option is > marked "obsolete"). I think gold should honor -m option to avoid generating incorrect output.
In llvm gold plugin tests, there are test/tools/gold/PowerPC/mtriple.ll:; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so -m elf32ppc \ test/tools/gold/X86/bcsection.ll:; RUN: %gold -r -o %T/bcsection.o -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so %T/bcsection.bco test/tools/gold/X86/emit-llvm.ll:; RUN: -m elf_x86_64 --plugin-opt=save-temps \ test/tools/gold/X86/emit-llvm.ll:; RUN: -m elf_x86_64 --plugin-opt=disable-output \ test/tools/gold/X86/parallel.ll:; RUN: env LD_PRELOAD=%llvmshlibdir/LLVMgold.so %gold -plugin %llvmshlibdir/LLVMgold.so -u foo -u bar -plugin-opt jobs=2 -plugin-opt save-temps -m elf_x86_64 -o %t %t.bc test/tools/gold/X86/pr19901.ll:; RUN: -shared -m elf_x86_64 -o %t.so %t2.o %t.o test/tools/gold/X86/remarks.ll:; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \ test/tools/gold/X86/remarks.ll:; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \ test/tools/gold/X86/slp-vectorize.ll:; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \ test/tools/gold/X86/vectorize.ll:; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \ On Linux/x86-64, if I remove -m elf32ppc from test/tools/gold/PowerPC/mtriple.ll, I get [hjl@gnu-6 bin]$ ./llvm-lit --verbose /export/gnu/import/git/llvm/test/tools/gold/PowerPC/mtriple.ll -- Testing: 1 tests, 1 threads -- FAIL: LLVM :: tools/gold/PowerPC/mtriple.ll (1 of 1) ******************** TEST 'LLVM :: tools/gold/PowerPC/mtriple.ll' FAILED ******************** Script: -- llvm-as /export/ssd/git/llvm/test/tools/gold/PowerPC/mtriple.ll -o /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp.o /export/build/gnu/binutils-gold/release/usr/local/bin/ld.gold -plugin /export/build/gnu/llvm-clang/build-x86_64-linux/./lib/LLVMgold.so -plugin-opt=mtriple=powerpc-linux-gnu -plugin-opt=obj-path=/export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp3.o -shared /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp.o -o /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp2 llvm-readobj --file-headers /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp2 | FileCheck --check-prefix=DSO /export/ssd/git/llvm/test/tools/gold/PowerPC/mtriple.ll llvm-readobj --file-headers /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp3.o | FileCheck --check-prefix=REL /export/ssd/git/llvm/test/tools/gold/PowerPC/mtriple.ll -- Exit Code: 1 Command Output (stderr): -- /export/build/gnu/binutils-gold/release/usr/local/bin/ld.gold: error: /export/build/gnu/llvm-clang/build-x86_64-linux/test/tools/gold/PowerPC/Output/mtriple.ll.tmp3.o: incompatible target -- ******************** Testing Time: 0.02s ******************** Failing Tests (1): LLVM :: tools/gold/PowerPC/mtriple.ll Unexpected Failures: 1 [hjl@gnu-6 bin]$ It shows that -m elf32ppc is required.
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6457197210144f50a696097c0d308d81d46d5510 commit 6457197210144f50a696097c0d308d81d46d5510 Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Oct 16 08:04:58 2015 -0700 Don't ignore "-m emulation" command line option Gold shouldn't ignore "-m emulation" command line option, which may lead to incorrect output. PR gold/19119 * options.h (General_options): Remove "obsolete" from -m. * parameters.cc (set_parameters_target): Check if input target is compatible with output emulation set by "-m emulation".
Fixed.
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=96f9814df23564e16909bb5ba00de4a202c63417 commit 96f9814df23564e16909bb5ba00de4a202c63417 Author: Cary Coutant <ccoutant@gmail.com> Date: Thu Nov 5 12:59:02 2015 -0800 Revert patch for PR 19119, which led to PR 19172 and 19197. Gold does not support all the emulations that Gnu ld does, and supports only one spelling per target. The -m option is used only in the rare case where there are no ELF input files, and we produce an empty output file. In those cases, users are expected to supply a -m option naming one of the supported emulations. In the many cases where a build script provides an unnecessary -m option naming an emulation that gold does not support, we will simply ignore the option, as we did before the reverted patch. gold/ PR gold/19119 PR gold/19172 PR gold/19197 Revert commit 6457197210144f50a696097c0d308d81d46d5510: 2015-10-16 H.J. Lu <hongjiu.lu@intel.com> * options.h (General_options): Remove "obsolete" from -m. * parameters.cc (set_parameters_target): Check if input target is compatible with output emulation set by "-m emulation".
The fix for this bug caused PR 19172 and PR 19197, so I'm reverting the patch and declaring this as "won't fix".
Just for the record, when -m is really used to select the correct emulation, gold and ld may require different emulations since ld may not be able to use the one working for gold and gold may ignore the one used by ld.