pussuw commented on PR #12853:
URL: https://github.com/apache/nuttx/pull/12853#issuecomment-2270842965
I would appreciate if someone who actually knows the elf file format better
could chime in on this.
When building nsh (used as init) as a relocatable elf file, this is what the
linker produces when using the nuttx gnu-elf.ld linker script:
```ville@workpc:~/Desktop/Kernelmode/cxx_bad_relocation$ objdump -hw init
objdump: Warning: Bogus end-of-siblings marker detected at offset 3e9 in
.debug_info section
objdump: Warning: Bogus end-of-siblings marker detected at offset 403 in
.debug_info section
objdump: Warning: Bogus end-of-siblings marker detected at offset 404 in
.debug_info section
objdump: Warning: Further warnings about bogus end-of-sibling markers
suppressed
objdump: Warning: DIE at offset 0x433 refers to abbreviation number 955
which does not exist
init: file format elf64-little
Sections:
Idx Name Size VMA LMA
File off Algn Flags
0 .text 0000adde 0000000000000000 0000000000000000
00000040 2**1 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .rodata 0000234c 000000000000ade0 000000000000ade0
0000ae20 2**3 CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
2 .srodata.g_nullstring 00000009 0000000000000000 0000000000000000
0000d170 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .srodata.cst8 00000030 0000000000000000 0000000000000000
0000d180 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .srodata.g_arg_separator 00000003 0000000000000000 0000000000000000
0000d1b0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .srodata.g_exitstatus 00000002 0000000000000000 0000000000000000
0000d1b8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .srodata.g_failure 00000002 0000000000000000 0000000000000000
0000d1c0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .srodata.g_line_separator 00000006 0000000000000000 0000000000000000
0000d1c8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .srodata.g_quote_separator 00000004 0000000000000000 0000000000000000
0000d1d0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .srodata.g_redirect1 00000002 0000000000000000 0000000000000000
0000d1d8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .srodata.g_redirect2 00000003 0000000000000000 0000000000000000
0000d1e0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .srodata.g_success 00000002 0000000000000000 0000000000000000
0000d1e8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
12 .srodata.g_token_separator 00000004 0000000000000000 0000000000000000
0000d1f0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
13 .srodata.g_erasetoeol 00000003 0000000000000000 0000000000000000
0000d1f8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
14 .srodata.g_home 00000002 0000000000000000 0000000000000000
0000d200 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .srodata.g_oldpwd 00000007 0000000000000000 0000000000000000
0000d208 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .srodata.g_pwd 00000004 0000000000000000 0000000000000000
0000d210 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .srodata.cst4 0000000c 0000000000000000 0000000000000000
0000d214 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA
18 .srodata.g_flags 00000007 0000000000000000 0000000000000000
0000d220 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
19 .srodata.g_groupid 00000007 0000000000000000 0000000000000000
0000d228 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
20 .srodata.g_state 00000007 0000000000000000 0000000000000000
0000d230 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
21 .srodata.g_type 00000006 0000000000000000 0000000000000000
0000d238 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
22 .srodata.g_unknown 00000008 0000000000000000 0000000000000000
0000d240 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
23 .data 00000048 0000000000000008 0000000000000008
0000d248 2**3 CONTENTS, ALLOC, LOAD, DATA
24 .sdata.__dso_handle 00000008 0000000000000000 0000000000000000
0000d290 2**3 CONTENTS, ALLOC, LOAD, RELOC, DATA
25 .sdata.g_syslog_mask 00000001 0000000000000000 0000000000000000
0000d298 2**0 CONTENTS, ALLOC, LOAD, DATA
26 .ctors 00000000 0000000000000001 0000000000000001
0000d299 2**0 CONTENTS
27 .dtors 00000000 0000000000000001 0000000000000001
0000d299 2**0 CONTENTS
28 .bss 0000054c 0000000000000008 0000000000000008
0000d2a0 2**3 ALLOC
29 .tdata 00000000 0000000000000554 0000000000000554
0000d2a0 2**0 CONTENTS, ALLOC, LOAD, DATA, THREAD_LOCAL
30 .tbss 00000000 0000000000000554 0000000000000554
0000d2a0 2**0 ALLOC, THREAD_LOCAL
31 .comment 000023cb 0000000000000000 0000000000000000
0000d2a0 2**0 CONTENTS, READONLY
32 .riscv.attributes 00000035 0000000000000000 0000000000000000
0000f66b 2**0 CONTENTS, READONLY
33 .debug_abbrev 0000f594 0000000000000000 0000000000000000
0000f6a0 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
34 .debug_info 00037cd9 0000000000000000 0000000000000000
0001ec34 2**0 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
35 .debug_line 000282b5 0000000000000000 0000000000000000
0005690d 2**0 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
36 .debug_aranges 00002d40 0000000000000000 0000000000000000
0007ebd0 2**4 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
37 .debug_loc 00020cae 0000000000000000 0000000000000000
00081910 2**0 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
38 .debug_ranges 00003ac0 0000000000000000 0000000000000000
000a25be 2**0 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
39 .debug_str 00036e1b 0000000000000000 0000000000000000
000a607e 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
40 .debug_frame 00004598 0000000000000000 0000000000000000
000dcea0 2**3 CONTENTS, RELOC, READONLY, DEBUGGING, OCTETS
```
As can be seen, the .ctor and .dtor sections are empty, and not allocated. I
think this is expected.
If I use the RISC-V GNU toolchain to do final linking, it assigns LMA and
VMA addresses for .ctors and .dtors. This is why nsh works as init with e.g.
our qemu rv-virt:knsh targets; the VMA address is set!
```
ville@workpc:~/Desktop/Kernelmode/cxx_bad_relocation$ objdump -hw a.out
a.out: file format elf64-little
Sections:
Idx Name Size VMA LMA
File off Algn Flags
0 .text 00009db8 00000000c0000000 00000000c0000000
00001000 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .rodata 0000234c 00000000c0009db8 00000000c0009db8
0000adb8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .srodata.g_nullstring 00000009 00000000c000c108 00000000c000c108
0000d108 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .srodata.cst8 00000030 00000000c000c118 00000000c000c118
0000d118 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .srodata.g_arg_separator 00000003 00000000c000c148 00000000c000c148
0000d148 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .srodata.g_exitstatus 00000002 00000000c000c150 00000000c000c150
0000d150 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .srodata.g_failure 00000002 00000000c000c158 00000000c000c158
0000d158 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .srodata.g_line_separator 00000006 00000000c000c160 00000000c000c160
0000d160 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .srodata.g_quote_separator 00000004 00000000c000c168 00000000c000c168
0000d168 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .srodata.g_redirect1 00000002 00000000c000c170 00000000c000c170
0000d170 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .srodata.g_redirect2 00000003 00000000c000c178 00000000c000c178
0000d178 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .srodata.g_success 00000002 00000000c000c180 00000000c000c180
0000d180 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
12 .srodata.g_token_separator 00000004 00000000c000c188 00000000c000c188
0000d188 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
13 .srodata.g_erasetoeol 00000003 00000000c000c190 00000000c000c190
0000d190 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
14 .srodata.g_home 00000002 00000000c000c198 00000000c000c198
0000d198 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .srodata.g_oldpwd 00000007 00000000c000c1a0 00000000c000c1a0
0000d1a0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .srodata.g_pwd 00000004 00000000c000c1a8 00000000c000c1a8
0000d1a8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .srodata.cst4 0000000c 00000000c000c1ac 00000000c000c1ac
0000d1ac 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA
18 .srodata.g_flags 00000007 00000000c000c1b8 00000000c000c1b8
0000d1b8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
19 .srodata.g_groupid 00000007 00000000c000c1c0 00000000c000c1c0
0000d1c0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
20 .srodata.g_state 00000007 00000000c000c1c8 00000000c000c1c8
0000d1c8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
21 .srodata.g_type 00000006 00000000c000c1d0 00000000c000c1d0
0000d1d0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
22 .srodata.g_unknown 00000008 00000000c000c1d8 00000000c000c1d8
0000d1d8 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA
23 .data 00000048 00000000c000c1e0 00000000c000c1e0
0000d1e0 2**3 CONTENTS, ALLOC, LOAD, DATA
24 .sdata.__dso_handle 00000008 00000000c000c228 00000000c000c228
0000d228 2**3 CONTENTS, ALLOC, LOAD, DATA
25 .sdata.g_syslog_mask 00000001 00000000c000c230 00000000c000c230
0000d230 2**0 CONTENTS, ALLOC, LOAD, DATA
26 .ctors 00000000 00000000c000c231 00000000c000c231
0000d784 2**0 CONTENTS
27 .dtors 00000000 00000000c000c231 00000000c000c231
0000d784 2**0 CONTENTS
28 .bss 0000054c 00000000c000c238 00000000c000c238
0000d231 2**3 ALLOC
29 .tdata 00000000 00000000c000c784 00000000c000c784
0000d784 2**0 CONTENTS, ALLOC, LOAD, DATA, THREAD_LOCAL
30 .tbss 00000000 00000000c000c784 00000000c000c784
0000d784 2**0 ALLOC, THREAD_LOCAL
31 .comment 00000030 0000000000000000 0000000000000000
0000d784 2**0 CONTENTS, READONLY
32 .riscv.attributes 00000035 0000000000000000 0000000000000000
0000d7b4 2**0 CONTENTS, READONLY
33 .debug_abbrev 0000f594 0000000000000000 0000000000000000
0000d7e9 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
34 .debug_info 00037cd9 0000000000000000 0000000000000000
0001cd7d 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
35 .debug_line 000282b5 0000000000000000 0000000000000000
00054a56 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
36 .debug_aranges 00002d40 0000000000000000 0000000000000000
0007cd10 2**4 CONTENTS, READONLY, DEBUGGING, OCTETS
37 .debug_loc 00020cae 0000000000000000 0000000000000000
0007fa50 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
38 .debug_ranges 00003ac0 0000000000000000 0000000000000000
000a06fe 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
39 .debug_str 000046ab 0000000000000000 0000000000000000
000a41be 2**0 CONTENTS, READONLY, DEBUGGING, OCTETS
40 .debug_frame 00004598 0000000000000000 0000000000000000
000a8870 2**3 CONTENTS, READONLY, DEBUGGING, OCTETS
```
However, prior to this patch, the VMA address was _not_ set by the nuttx
binfmt elfloader, which causes a the crash mentioned in the commit message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]