#3740 assigned defect

Libld does not load incrementially linked object file

Reported by: Chris Johns Owned by: Chris Johns
Priority: normal Milestone: 5.1
Component: lib/dl Version: 5
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

If separate object files have the same local symbol and are incrementally linked libdl only uses the first symbol found.

The issue has been raised by Peter in a post to devel:

https://lists.rtems.org/pipermail/devel/2019-April/025623.html

The issue can be shown with:

$ cat foo.c
#include <stdio.h>

extern void foo(void);
void foo(void)
{
    printf("FOO %s\n", "Foo 1");
}
$ cat bar.c
#include <stdio.h>

extern void bar(void);
void bar(void)
{
    printf("BAR %s\n", "Bar 1");
}
$ arm-rtems5-gcc -march=armv7-a -mthumb -c foo.c
$ arm-rtems5-gcc -march=armv7-a -mthumb -c bar.c
$ arm-rtems5-ld -r -o fubar bar.o foo.o
$ arm-rtems5-readelf -s fubar

Symbol table '.symtab' contains 20 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
     2: 00000000     0 SECTION LOCAL  DEFAULT    3 
     3: 00000000     0 SECTION LOCAL  DEFAULT    4 
     4: 00000000     0 SECTION LOCAL  DEFAULT    5 
     5: 00000000     0 SECTION LOCAL  DEFAULT    6 
     6: 00000000     0 SECTION LOCAL  DEFAULT    7 
     7: 00000000     0 FILE    LOCAL  DEFAULT  ABS bar.c
     8: 00000000     0 NOTYPE  LOCAL  DEFAULT    3 $d
     9: 00000000     0 NOTYPE  LOCAL  DEFAULT    3 .LC0
    10: 00000008     0 NOTYPE  LOCAL  DEFAULT    3 .LC1
    11: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $t
    12: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.c
    13: 00000010     0 NOTYPE  LOCAL  DEFAULT    3 $d
    14: 00000010     0 NOTYPE  LOCAL  DEFAULT    3 .LC0
    15: 00000018     0 NOTYPE  LOCAL  DEFAULT    3 .LC1
    16: 0000001c     0 NOTYPE  LOCAL  DEFAULT    1 $t
    17: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND printf
    18: 0000001d    28 FUNC    GLOBAL DEFAULT    1 foo
    19: 00000001    28 FUNC    GLOBAL DEFAULT    1 bar
$ arm-rtems5-objdump --disassemble --source fubar

fubar:     file format elf32-littlearm

Disassembly of section .text:

00000000 <bar>:
   0:	b580      	push	{r7, lr}
   2:	af00      	add	r7, sp, #0
   4:	f240 0100 	movw	r1, #0
   8:	f2c0 0100 	movt	r1, #0
   c:	f240 0000 	movw	r0, #0
  10:	f2c0 0000 	movt	r0, #0
  14:	f7ff fffe 	bl	0 <printf>
  18:	bf00      	nop
  1a:	bd80      	pop	{r7, pc}

0000001c <foo>:
  1c:	b580      	push	{r7, lr}
  1e:	af00      	add	r7, sp, #0
  20:	f240 0100 	movw	r1, #0
  24:	f2c0 0100 	movt	r1, #0
  28:	f240 0000 	movw	r0, #0
  2c:	f2c0 0000 	movt	r0, #0
  30:	f7ff fffe 	bl	0 <printf>
  34:	bf00      	nop
  36:	bd80      	pop	{r7, pc}

Change History (1)

comment:1 Changed on Apr 26, 2019 at 9:10:02 PM by Chris Johns

I have updated dl01 adding the example code and build PowerPC and ARM bsps. The PowerPC BSP works while the ARM BSP does not work.

The results for the psim BSP is:

$ rtems-run --rtems-bsp=psim `find . -name dl01.exe`
RTEMS Testing - Run, 5.0.not_released
 Command Line: /opt/work/rtems/5/bin/rtems-run --rtems-bsp=psim ./powerpc-rtems5/c/psim/testsuites/libtests/dl01.exe
 Python: 3.6.6 (default, Oct  2 2018, 01:22:29) [GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 326565)]
Host: FreeBSD-12.0-RELEASE-p3-amd64-64bit-ELF (FreeBSD ruru 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC amd64 amd64)
OpenPIC Version ? (1 CPUs and 1 IRQ sources) at 0x202571776
OpenPIC Vendor 0 (Unknown), Device 0 (Unknown), Stepping 0
Overriding NumSources (1) from configuration with 16
OpenPIC timer frequency is not set
BATs must not overlap; area 0x08000000..0x09000000 hits DBAT 0
BATs must not overlap; area 0x0c000000..0x0d000000 hits DBAT 0
*** BEGIN OF TEST libdl (RTL) 1 ***
*** TEST VERSION: 5.0.0.be50969881b97180bf4fc1e2975efd41169e08bb-modified
*** TEST STATE: EXPECTED-PASS
*** TEST BUILD: RTEMS_POSIX_API
*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB d9f49fc117422ea4b039cebc668191e9c07fde25, Newlib 1d35a003f)
load: /dl01-o1.o
handle: 0x6f668 loaded
Loaded module: argc:2 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
  0: Line 1
  1: Line 2
Loaded module: argc:3 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
  0: Call 2, line 1
  1: Call 2, line 2
  2: Call 2, line 3
handle: 0x6f668 closed
load: /dl01-o2o3.o
handle: 0x6f668 loaded
FOO Foo 1
BAR Bar 1
handle: 0x6f668 closed
*** END OF TEST libdl (RTL) 1 ***
*** FATAL ***
fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT)
fatal code: 0 (0x00000000)
RTEMS version: 5.0.0.be50969881b97180bf4fc1e2975efd41169e08bb-modified
RTEMS tools: 7.4.0 20181206 (RTEMS 5, RSB d9f49fc117422ea4b039cebc668191e9c07fde25, Newlib 1d35a003f)
executing thread ID: 0x08a010001
executing thread name: UI1
Run time     : 0:00:01.032580

The results for the xilinx_zynq_a9_qemu is:

$ rtems-run --rtems-bsp=xilinx_zynq_a9_qemu `find . -name dl01.exe`
RTEMS Testing - Run, 5.0.not_released
 Command Line: /opt/work/rtems/5/bin/rtems-run --rtems-bsp=xilinx_zynq_a9_qemu ./arm-rtems5/c/xilinx_zynq_a9_qemu/testsuites/libtests/dl01.exe
 Python: 3.6.6 (default, Oct  2 2018, 01:22:29) [GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 326565)]
Host: FreeBSD-12.0-RELEASE-p3-amd64-64bit-ELF (FreeBSD ruru 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC amd64 amd64)

(process:90678): GLib-WARNING **: 07:02:48.995: gmem.c:490: custom memory allocation vtable not supported
Warning: nic cadence_gem.0 has no peer
Warning: nic cadence_gem.1 has no peer


*** BEGIN OF TEST libdl (RTL) 1 ***
*** TEST VERSION: 5.0.0.be50969881b97180bf4fc1e2975efd41169e08bb-modified
*** TEST STATE: EXPECTED-PASS
*** TEST BUILD: RTEMS_POSIX_API
*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB d9f49fc117422ea4b039cebc668191e9c07fde25, Newlib 1d35a003f)
load: /dl01-o1.o
handle: 0x117c98 loaded
Loaded module: argc:2 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
  0: Line 1
  1: Line 2
Loaded module: argc:3 [/opt/work/chris/rtems/kernel/rtems.git/c/src/../../testsuites/libtests/dl01/dl-o1.c]
  0: Call 2, line 1
  1: Call 2, line 2
  2: Call 2, line 3
handle: 0x117c98 closed
load: /dl01-o2o3.o
handle: 0x117c98 loaded
FOO Foo 1
FOO Foo 1
handle: 0x117c98 closed

*** END OF TEST libdl (RTL) 1 ***


*** FATAL ***
fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT)
fatal code: 0 (0x00000000)
RTEMS version: 5.0.0.be50969881b97180bf4fc1e2975efd41169e08bb-modified
RTEMS tools: 7.4.0 20181206 (RTEMS 5, RSB d9f49fc117422ea4b039cebc668191e9c07fde25, Newlib 1d35a003f)
executing thread ID: 0x08a010001
executing thread name: UI1

Run time     : 0:00:01.018158
Note: See TracTickets for help on using tickets.