<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62209>62209</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld: pointer remains blank in custom section
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          erenon
      </td>
    </tr>
</table>

<pre>
    My application stores a pointer to a string in a custom ELF section. lld leaves the pointer 0, while other linkers set it correctly.
Minimal repro:

```cpp
#include <cstdint>
#include <cstdio>

int main() {

  __attribute__((section(".custom"), used, retain))
  static constexpr const char* x[] = {
    __FILE__
 };
  const std::uint64_t id = std::uint64_t(&x);
  printf("%lu\n", id);
}
```
combined with:

```make
app: app.cpp
        $(CXX) $< -o $@ -fuse-ld=$(LD)

test: app
        readelf -x .custom $<
```
Test cases:

```shell
$ CXX=$(which clang++) LD=bfd make test -B    # ok
$ CXX=$(which clang++) LD=gold make test -B  # ok
$ CXX=$(which clang++) LD=lld make test -B     # BROKEN
$ CXX=$(which g++) LD=bfd make test -B    # ok
$ CXX=$(which g++) LD=gold make test -B  # ok
$ CXX=$(which g++) LD=lld make test -B     # BROKEN
```

Example good output:

```
$ readelf -x .custom app

Hex dump of section '.custom':
  0x00002020 44070000 00000000 D.......
```

Example bad output:

```
$ readelf -x .custom app

Hex dump of section '.custom':
  0x000039e8 00000000 00000000 ........
```

Versions:

```
$ clang++ -v       
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ ld.lld -v
Ubuntu LLD 14.0.0 (compatible with GNU linkers)
```
</pre>
<img width="1px" height="1px" alt="" src="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