[PATCH] D28898: [ELF] - Allow emulation to be different from input objects target.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 02:58:38 PST 2017


grimar added a comment.

In https://reviews.llvm.org/D28898#652502, @ruiu wrote:

> I found that arch/x86/realmode/rm/realmode.lds.S has an OUTPUT_FORMAT directive, which is ignored by LLD at the moment. Isn't this the cause of the problem?


I think it is not. GNU linkers are very inconsistent. Ignoring OUTPUT_FORMAT seems to be OK.
See my experiments results:

Lets say we have next 4 scripts and trying to link i386 objects with -m elf_x86_64 (just like PR31678):
**1) First that has OUTPUT_FORMAT and OUTPUT_ARCH**

  OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
  OUTPUT_ARCH(i386)
  SECTIONS { ... }

**Linker: result**
**BFD**: YES
**GOLD**: YES, output is i386 in both cases.

**2) Second has only OUTPUT_FORMAT:**

  OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
  SECTIONS { ... }

**BFD**: YES and output is x86_64. That looks wierd result for i386 objects inputs, right ? 
And if I add --emit-relocs, I see that it emits tons of NONE relocations instead of i386 ones:

  Relocation section '.rel.text' at offset 0x2061b8 contains 131 entries:
    Offset          Info           Type           Sym. Value    Sym. Name
  000000000000  000000000000 R_X86_64_NONE    
  000000000000  000000000000 R_X86_64_NONE    
  000000000000  000000000000 R_X86_64_NONE 

So it looks output is some kind of 'forced'.

**GOLD**: YES and output is i386.

**3) Third has only OUTPUT_ARCH:**

  OUTPUT_ARCH(i386)
  SECTIONS { ... }

**BFD**: NO
ld.bfd: i386 architecture of input file `home/umb/linux_kernel/linux/linux/arch/x86/realmode/rm/header.o' is incompatible with i386:x86-64 output

**GOLD**: YES and output is i386.

**4) Fourth has nothing:**

  SECTIONS { ... }

**BFD**: NO

  ld.bfd: i386 architecture of input file `home/umb/linux_kernel/linux/linux/arch/x86/realmode/rm/header.o' is incompatible with i386:x86-64 output

**GOLD**: YES, output is i386

So looks gold takes output format from inputs and ignores OUTPUT_FORMAT/OUTPUT_ARCH, just like we do.
Taking machine format from inputs and overriding -m seems very simple logic that is easy to understand and solves initial problem,
it is consistent with gold.
In my opinion gold behavior is much simpler than what bfd tries to do and we can try to stick to it.


https://reviews.llvm.org/D28898





More information about the llvm-commits mailing list