<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang or lld generates invalid short relocation for Google Chrome with debuginfo"
   href="https://bugs.llvm.org/show_bug.cgi?id=43942">43942</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang or lld generates invalid short relocation for Google Chrome with debuginfo
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>conrad.meyer@isilon.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Possibly related to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - RuntimeDyldELF doesn't handle >2GB relocations on x86-64 platforms"
   href="show_bug.cgi?id=15356">bug 15356</a> or <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - On x86_64 ELF, short relocation can be produced even in large code model"
   href="show_bug.cgi?id=21423">bug 21423</a>.

When linking a debug build of recent Chrome (78.x), with recent Clang+LLD
(9.0.0), ld.lld fails due to 32-bit relocations on >4GB offsets:

<span class="quote">> ld.lld: error: /usr/lib/crtn.o:(.debug_aranges+0x6): relocation R_X86_64_32 out of range: 4357891405 is not in [0, 4294967295]; consider recompiling with -fdebug-types-section to reduce size of debug sections</span >

I'm not sure what I'm supposed to do about this as an end-user.  Chrome is just
a gigantic program:

$ c++ -Wl,--version-script=../../build/linux/chrome.map -fPIC
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=lld -Wl,--color-diagnostics
-m64 -rdynamic -pie -Wl,--disable-new-dtags -L/usr/local/lib
-L/usr/local/lib/nss  -fstack-protector-strong -L/usr/local/lib  -o "./chrome"
-Wl,--start-group @"./chrome.rsp"  -Wl,--end-group ... (-lfoo -lbar from here)

$ cat chrome.rsp  | tr ' ' '\0' | xargs -0 du -csh
...
3.7G

Should Clang (or lld?) emit 64-bit relocations automatically?  Do I need to ask
the Chrome folks to use some large data mode flag?  They already use -fPIC
rather than
-fpic.

       -fPIC
           If supported for the target machine, emit position-independent
           code, suitable for dynamic linking and avoiding any limit on the
           size of the global offset table.

(From the gcc manual page.)  Also gcc:

       -mcmodel=small
           Generate code for the small code model: the program and its symbols
           must be linked in the lower 2 GB of the address space.  Pointers
           are 64 bits.  Programs can be statically or dynamically linked.
           This is the default code model.

       -mcmodel=medium
           Generate code for the medium model: the program is linked in the
           lower 2 GB of the address space.  Small symbols are also placed
           there.  Symbols with sizes larger than -mlarge-data-threshold are
           put into large data or BSS sections and can be located above 2GB.
           Programs can be statically or dynamically linked.

       -mcmodel=large
           Generate code for the large model.  This model makes no assumptions
           about addresses and sizes of sections.

Here's Clang's full documentation on -mcmodel:

<a href="https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mcmodel">https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mcmodel</a>

(Yeah, that's not helpful.)

Maybe -mcmodel is passed through to cc1 as -mcode-model= here:
<a href="https://github.com/llvm/llvm-project/blob/master/clang/lib/Driver/ToolChains/Clang.cpp#L4320">https://github.com/llvm/llvm-project/blob/master/clang/lib/Driver/ToolChains/Clang.cpp#L4320</a>

The scenario seems pretty similar to this test case:
<a href="https://github.com/llvm/llvm-project/blob/master/lld/test/ELF/x86-64-reloc-debug-overflow.s">https://github.com/llvm/llvm-project/blob/master/lld/test/ELF/x86-64-reloc-debug-overflow.s</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>