[llvm-bugs] [Bug 37432] New: OUTPUT_FORMAT from linker script doesn't override the -m flag

via llvm-bugs llvm-bugs at lists.llvm.org
Sat May 12 06:35:21 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37432

            Bug ID: 37432
           Summary: OUTPUT_FORMAT from linker script doesn't override the
                    -m flag
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: dima at golovin.in
                CC: llvm-bugs at lists.llvm.org

For GNU ld OUTPUT_FORMAT overrides the -m flag (and Linux relies on this
behavior when linking realmode.elf on x86_64), for LLD it doesn't.

How to reproduce (on modern x86_64 Linux with recent clang and lld):

 - create an example object file for i386:

    clang -c -m32 -x c -o test.o /dev/null

 - create an example linker script with the following content:

    OUTPUT_FORMAT(elf32-i386)
    OUTPUT_ARCH(i386)
    SECTIONS {
            . = 0x00000000;
            .text : {
                    test.o (.text);
            }
    }

 - try linking using wrong -m flag: ld.lld -m elf_x86_64 -T test.lds -o
test.elf test.o

Expected result:

Output format information from the linker script is used (the -m flag is
ignored) and an ELF binary is produced. This is at least how bfd and gold from
GNU binutils 2.29.1 behave.

Actual result:

Output format from -m flag is used (OUTPUT_FORMAT in the linker script is
ignored) and the following error is produced: ld.lld: error: test.o is
incompatible with elf_x86_64


I don't insist that GNU implementation is correct and lld is not, I don't know
if any standard actually covers this, I just think that ld.lld should be
compatible with GNU utilities, so it can be used as a drop-in replacement.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180512/6e512b95/attachment.html>


More information about the llvm-bugs mailing list