<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 - Issue with GOT section and static linking"
   href="https://bugs.llvm.org/show_bug.cgi?id=43401">43401</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Issue with GOT section and static linking
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eblot.ml@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Context: LLVM 9.0 (final), ARMv7em baremetal, C/C++, no shared libraries.

I'm having trouble using LLD to link a C++ application when some of LLVM's
libc++.a API is used, for example iostream.

I cannot reproduce the following issues with GNU LD, but it seems it does not
work the same way as LLD on this topic.

The initial issue is:
  ld.lld: error: no memory region specified for section '.got'

There is no .got section definition in many, if not most, ARM baremetal LD
scripts, and I do not understand why the compiler (LLVM Clang) generates such
sections with static libraries, as I understand .got sections are dedicated to
deal with shared libraries.

GNU LD automatically adds a `.got` section to the final ELF executable, even
when not specified in the linker script. Hence, this problem does not arise
with GNU LD.

Anyway, adding a `.got` section to the LLVM LLD linker script helps to some
point with features of libc++.a, but a new error arises when iostream API is
used. This error is:

  ld.lld: error: section: .got is not contiguous with other relro sections

I'm not fluent at all with RELRO and the like, but again it seems tightly
coupled to dynamic loading, which is far away from ARM baremetal static
targets.

I've been unable to find a way to workaround this issue, because:

1. existing baremetal ARM environments usually provides LD scripts which are
quite hard to wring them so they get compliant with what seems to be required
for LLD, if I understand the constraints expressed in
lld/ELF/Writer.cpp:isRelroSection()

2. there is not dynamic loaded in a statically built environment, so it seems
the purpose of RELRO does not apply to this kind of environment

3. it is quite hard (without using a debugger against LLD) to figure out what
are the real constraints that trigger this error message, i.e. which section
has been considered as a RELRO candidate.

Anyway:
 1- Is it valid to consider .got sections for a statically linked, baremetal
application?
 2- Is there a way to disable the unique, contiguous RELRO section checks?

If it is valid to consider .got and .relro sections for ARM statically linked
baremetal applications, is there a recommended approach to sort this out,
because for now, I have found no valid example on how to write a LLD-compliant
linker script for this environment while linking against libc++.a / libc++abi.a
static libraries.

Thanks.</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>