Issue created by Anthony Cole: 
https://gitlab.rtems.org/rtems/tools/rtems-tools/-/work_items/48



**Summary**

`output_sym::operator()` in `linkers/rtems-syms.cpp` means to skip weak symbols 
without a value:

```c++
  /*
   * Weak symbols without a value are probably unresolved externs. Ignore them.
   */
  if (weak && sym.value () == 0)
    return;
```

but every `output_sym` is constructed with `weak` = `false` (in `generate_c()`, 
for the symbols, TLS count, TLS functions and TLS call table), so the check 
never applies. A weak undefined symbol of the base image is written to the 
generated symbol table, which refers to it strongly, and the final link fails 
with an undefined symbol.

**How it shows**

With a C library that refers to a symbol weakly and doesn't define it, for 
example a newlib whose `__call_atexit.c` refers to `__libc_fini` weakly, every 
libdl test (`dl01`, `dl02`, `dl04`...) fails to link after `rtems-syms -e -S`:

```
ld.lld: error: undefined symbol: __libc_fini
>>> referenced by dl11-sym.c
```

The `.pre` image has it as `WEAK UND` with value 0. RTEMS's own newlib doesn't 
refer to `__libc_fini`, so RTEMS's toolchain doesn't hit this.

**Fix**

Construct the `output_sym` objects for the weak symbols with `weak` = `true`, 
or simply skip any symbol that is undefined in the base image (`STB_WEAK` with 
`SHN_UNDEF`) when collecting the symbols. A workaround is a filter that leaves 
the symbol out: `rtems-syms -F '(?!__libc_fini$).*' ...`.

**Environment**

rtems-tools d79edad28679eed3e7014086df1ccbe2b2678119 (RSB 7, `7/rtems-riscv`), 
`rtems-syms` 7.74fffa09a3df. Found building RTEMS's libdl tests with the 
Codasip SDK (clang 19, LLVM's lld, a bare-metal newlib).

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/tools/rtems-tools/-/work_items/48
You're receiving this email because of your account on gitlab.rtems.org. 
Unsubscribe from this thread: 
https://gitlab.rtems.org/-/namespace/13/sent_notifications/6-8giwdxaq2c77278h3nmuzbkuj-d/unsubscribe
 | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | 
Help: https://gitlab.rtems.org/help


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to