#2704 closed defect (fixed)

Weak symbols not found by loaded code

Reported by: Patrick Gauvin Owned by: Chris Johns
Priority: normal Milestone:
Component: lib/dl Version: 4.11
Severity: normal Keywords: libdl, weak symbol
Cc: Joel Sherrill Blocked By:
Blocking:

Description

In the attached test case, the symbol base_func is defined weakly in the base image. The loaded object has a reference to base_func, and the loader is unable to resolve it:

Unresolved symbols: 1 (dlerror: global symbol not found: base_func)

The expected behavior is for the reference to be resolved to the weak base_func, since there is no globally exported symbol with the same name present. Note that base_func does not show up in the initial rtl: esyms: ... messages.

Possibly of note, if base_func is defined in the loaded object (weak or not), its base_func reference is resolved to the symbol in the loaded object at load time, BUT the base image still uses its own base_func (even if the loaded base_func is not weak). This can be tested by uncommenting lines at the end of lib.c.

Steps to reproduce (you may have to edit BSP_DIR in the Makefile):

make clean all
qemu-system-arm -m 256M -M xilinx-zynq-a9 -serial null -serial mon:stdio -nographic \
  -no-reboot -kernel libdl-weak-sym-test.exe

Development Environment:

arm-rtems4.11-gcc (GCC) 4.9.3 20150626 (RTEMS 4.11, RSB aa3fdad01a0dbc3cbfd7c49e1ea07ff1a585c0b9 (HEAD, origin/4.11, 4.11)-modified, Newlib 2.2.0.20150423)

  • RTEMS Configure Options:

--target=arm-rtems4.11 --enable-rtemsbsp="xilinx_zynq_a9_qemu xilinx_zynq_zedboard xilinx_zynq_csp_cots xilinx_zynq_csp_hybrid" --enable-tests=samples --enable-posix --prefix=$HOME/development/rtems/4.11 --disable-networking

Attachments (2)

libdl-weak-sym-test.tar.gz (1.5 KB) - added by Patrick Gauvin on May 10, 2016 at 9:17:23 PM.
rtems-syms-include-weaks.patch (958 bytes) - added by Patrick Gauvin on Jun 26, 2016 at 5:47:45 PM.
Temporary workaround

Download all attachments as: .zip

Change History (8)

Changed on May 10, 2016 at 9:17:23 PM by Patrick Gauvin

Attachment: libdl-weak-sym-test.tar.gz added

comment:1 Changed on Jun 7, 2016 at 10:38:08 PM by Ryan Slabaugh

Just ran into this same issue during development. Any new status on this ticket?

Changed on Jun 26, 2016 at 5:47:45 PM by Patrick Gauvin

Temporary workaround

comment:2 Changed on Jun 26, 2016 at 5:55:52 PM by Patrick Gauvin

I've attached a patch for rtems-syms in rtems-tools that includes any defined weak symbols in the base image into the symbol table it generates. This allows loaded code to find the symbols, but it is not a complete solution, since now a defined weak symbol in loaded code will cause a failed load if it is defined in the base image weakly, since the loader now believes it is a strong symbol. For what it's worth, the x86_64 loader on Linux seems to use the base's symbol in situations where the symbol is defined in both the base and loaded code (regardless of whether they are weak or strong).

comment:3 Changed on Aug 25, 2016 at 5:58:07 AM by Chris Johns <chrisj@…>

Resolution: fixed
Status: newclosed

In ef4a46e0293111361c970a287c29a185905121b2/rtems-tools:

linkers/syms: Add weak symbols to the global symbol table.

Add any weak symbols that have been linked into the base image to the
global symbol table. A weak symbol is global when view viewed from
a dynamically loaded module.

Closes #2704.

comment:4 Changed on Aug 25, 2016 at 5:58:24 AM by Chris Johns <chrisj@…>

In 885aebd6b34755198196a96825fc82b9fc4a0789/rtems-tools:

linkers/syms: Add weak symbols to the global symbol table.

Add any weak symbols that have been linked into the base image to the
global symbol table. A weak symbol is global when view viewed from
a dynamically loaded module.

Closes #2704.

comment:5 Changed on Nov 16, 2016 at 12:18:01 AM by Chris Johns <chrisj@…>

In ef4a46e0293111361c970a287c29a185905121b2/rtems-tools:

linkers/syms: Add weak symbols to the global symbol table.

Add any weak symbols that have been linked into the base image to the
global symbol table. A weak symbol is global when view viewed from
a dynamically loaded module.

Closes #2704.

comment:6 Changed on Nov 18, 2016 at 8:35:31 PM by Chris Johns <chrisj@…>

In ef4a46e0293111361c970a287c29a185905121b2/rtems-tools:

linkers/syms: Add weak symbols to the global symbol table.

Add any weak symbols that have been linked into the base image to the
global symbol table. A weak symbol is global when view viewed from
a dynamically loaded module.

Closes #2704.

Note: See TracTickets for help on using tickets.