[llvm-bugs] [Bug 37331] New: lld-link x86-64: undefined weak symbol does not resolve to 0

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 3 15:36:17 PDT 2018


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

            Bug ID: 37331
           Summary: lld-link x86-64: undefined weak symbol does not
                    resolve to 0
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: COFF
          Assignee: unassignedbugs at nondot.org
          Reporter: sheu+bugs.llvm.org at google.com
                CC: llvm-bugs at lists.llvm.org

Instead of resolving to 0, an undefined weak symbol resolves to (in this case)
0x100000000 (that's right, 33 bits, not a typo).

This only occurs when linking for x86-64; the symbol resolves correctly to 0x0
for x86.

Test case source:

void foo() __attribute__((weak));

int main(int argc, char** argv) {
  if (foo) {
    return 2;
  }
  return 1;
}


Build invocation, 64-bit:

./clang-cl -m64 -fuse-ld=lld-link /Zl noop.c -o noop_64.exe /link /entry:main


Disassembly of binary (with objdump -d):

noop_64.exe:     file format pei-x86-64


Disassembly of section .text:

0000000140001000 <.text>:
   140001000:   48 83 ec 18             sub    $0x18,%rsp
   140001004:   c7 44 24 14 00 00 00    movl   $0x0,0x14(%rsp)
   14000100b:   00 
   14000100c:   48 89 54 24 08          mov    %rdx,0x8(%rsp)
   140001011:   89 4c 24 04             mov    %ecx,0x4(%rsp)
   140001015:   48 8d 15 e4 ef ff bf    lea    -0x4000101c(%rip),%rdx        #
0x100000000
   14000101c:   48 85 d2                test   %rdx,%rdx
   14000101f:   0f 84 12 00 00 00       je     0x140001037
   140001025:   e9 00 00 00 00          jmpq   0x14000102a
   14000102a:   c7 44 24 14 02 00 00    movl   $0x2,0x14(%rsp)
   140001031:   00 
   140001032:   e9 08 00 00 00          jmpq   0x14000103f
   140001037:   c7 44 24 14 01 00 00    movl   $0x1,0x14(%rsp)
   14000103e:   00 
   14000103f:   8b 44 24 14             mov    0x14(%rsp),%eax
   140001043:   48 83 c4 18             add    $0x18,%rsp
   140001047:   c3                      retq


Execution result on Windows:

C:\Users\sheu>noop_64.exe

C:\Users\sheu>echo %ERRORLEVEL%
2


The executable builds and runs correctly (returns '1') when building for
32-bit.

-- 
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/20180503/e9a2633f/attachment-0001.html>


More information about the llvm-bugs mailing list