Run time linker allocator locking hangs RTEMS

Peter Dufault dufault at hda.com
Fri Apr 26 21:35:49 UTC 2019


I found this trying to work on "#3740: Libld does not load incrementially linked object file”.  When I updated it hung loading the text segment (line 1005 in rtl-elf.c, hard hang, debug output below).  I tracked it down to a change that adds locking to the allocator.

- BSP: xilinx_zynq_a9_qemu.  Followed instructions in rtems-libbsd README.md.
- rtems version: works in bdec62c, broken in 22afb03.
- rtems-libbsd: You need to go back to before renaming of some SMP symbols, I went back to 5432c6b.

**** This is the change that broke it:
[dufault at gen6 rtems]$ git log --pretty=format:"%h %ad %s" bdec62c...22afb03
22afb03 Mon Feb 18 11:46:22 2019 +1100 libdl/alloc: Add a locking interface to the allocator.
[dufault at gen6 rtems]$ 

**** Loading works in bdec62c:
-> ld 0,0,"foo.o"
value = 4070648 = 0x3e1cf8
-> foo()
FOO
value = 10 = 0xa
-> 

**** Loading hangs in 22afb03:
-> ld 0,0,”foo.o”
**** HANG

**** GDB output during hang and info on (extremely simple) downloaded object.

In GDB attached to qemu you see the hang loading the text segment at line 1005 of rtl-elf.c:

(gdb) target remote :1234
Remote debugging using :1234
bsp_start_vector_table_end ()
    at /home/dufault/development/rtems/kernel/rtems/c/src/lib/libbsp/arm/xilinx-zynq/../../../../../../bsps/arm/shared/start/start.S:146
146		mov	r5, r1		/* machine type number or ~0 for DT boot */
(gdb) b rtl-elf.c:1005
Breakpoint 1 at 0x13a0a6: file /home/dufault/development/rtems/kernel/rtems/c/src/../../cpukit/libdl/rtl-elf.c, line 1005.
(gdb) c
Continuing.

Breakpoint 1, rtems_rtl_elf_loader (obj=0x3e1cf8, fd=43, sect=0x3e1eb8, data=0x2928a8)
    at /home/dufault/development/rtems/kernel/rtems/c/src/../../cpukit/libdl/rtl-elf.c:1005
1005	    ssize_t r = read (fd, base_offset, len);
(gdb) next
^C *** HANG HERE ***
Program received signal SIGINT, Interrupt.
0x0015bd4a in _CPU_Thread_Idle_body (ignored=0)
    at /home/dufault/development/rtems/kernel/rtems/c/src/../../cpukit/score/cpu/arm/armv7-thread-idle.c:32
32	    __asm__ volatile ("wfi");
(gdb) 

**** Info on downloaded object.  It’s just a simple “.o” file with extra symbols stripped.

Zynq dufault at gen6 fubar]$ cat foo.c
#include <stdio.h>
extern void foo(void);
void foo(void) {
    puts("FOO\n");
}
Zynq dufault at gen6 fubar]$ arm-rtems5-gcc -march=armv7-a -mthumb -c foo.c
Zynq dufault at gen6 fubar]$ arm-rtems5-strip --strip-unneeded foo.o
Zynq dufault at gen6 fubar]$ arm-rtems5-readelf --all foo.o
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          552 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 10

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000014 00  AX  0   0  2
  [ 2] .rel.text         REL             00000000 0001bc 000018 08   I  8   1  4
  [ 3] .data             PROGBITS        00000000 000048 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          00000000 000048 000000 00  WA  0   0  1
  [ 5] .rodata           PROGBITS        00000000 000048 000005 00   A  0   0  4
  [ 6] .comment          PROGBITS        00000000 00004d 000065 01  MS  0   0  1
  [ 7] .ARM.attributes   ARM_ATTRIBUTES  00000000 0000b2 00002f 00      0   0  1
  [ 8] .symtab           SYMTAB          00000000 0000e4 0000c0 10      9  10  4
  [ 9] .strtab           STRTAB          00000000 0001a4 000015 00      0   0  1
  [10] .shstrtab         STRTAB          00000000 0001d4 000051 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  y (purecode), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

There is no dynamic section in this file.

Relocation section '.rel.text' at offset 0x1bc contains 3 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000004  0000022f R_ARM_THM_MOVW_AB 00000000   .LC0
00000008  00000230 R_ARM_THM_MOVT_AB 00000000   .LC0
0000000c  00000b0a R_ARM_THM_CALL    00000000   puts

There are no unwind sections in this file.

Symbol table '.symtab' contains 12 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 $d
     2: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 .LC0
     3: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $t
     4: 00000000     0 SECTION LOCAL  DEFAULT    1 
     5: 00000000     0 SECTION LOCAL  DEFAULT    3 
     6: 00000000     0 SECTION LOCAL  DEFAULT    4 
     7: 00000000     0 SECTION LOCAL  DEFAULT    5 
     8: 00000000     0 SECTION LOCAL  DEFAULT    6 
     9: 00000000     0 SECTION LOCAL  DEFAULT    7 
    10: 00000001    20 FUNC    GLOBAL DEFAULT    1 foo
    11: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND puts

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_optimization_goals: Aggressive Debug
  Tag_CPU_unaligned_access: v6

**** Disassembly

Zynq dufault at gen6 fubar]$ arm-rtems5-objdump --disassemble --source foo.o

foo.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <foo>:
   0:	b580      	push	{r7, lr}
   2:	af00      	add	r7, sp, #0
   4:	f240 0000 	movw	r0, #0
   8:	f2c0 0000 	movt	r0, #0
   c:	f7ff fffe 	bl	0 <puts>
  10:	bf00      	nop
  12:	bd80      	pop	{r7, pc}
Zynq dufault at gen6 fubar]$ 

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering

This email is delivered through the public internet using protocols subject to interception and tampering.



More information about the devel mailing list