I have a very small program that should produce a data relocation:
#![no_std]
#![no_main]
#[no_mangle]
#[link_section = ".TEST"]
pub static TEST: &str = "TEST";
#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! { loop {} }
There should be a relocation entry that makes the exported fat pointer TEST
point to the string literal data. The .cargo/config.toml
I use is:
[target.x86_64-unknown-none]
rustflags = ["-C", "link-args=--oformat binary -T map.ld -Map target/x64.txt"]
[target.aarch64-unknown-none]
rustflags = ["-C", "link-args=--oformat binary -T map.ld -Map target/aarch64.txt"]
And the linker script is:
SECTIONS {
data 0 : {
KEEP(*(*.TEST))
*(.rodata*)
}
reloc : { *(.rel*) }
dynamic : { *(.dynamic) }
}
When building with cargo build --target x86_64-unknown-none --release
, the output map is:
VMA LMA Size Align Out In Symbol
0 0 14 8 data
0 0 10 8 D:\reloc-test\target\x86_64-unknown-none\release\deps\reloc_test-8849a06c43798340.reloc_test.5fe8bd3830097974-cgu.0.rcgu.o:(.TEST)
0 0 10 1 TEST
10 10 4 1 <internal>:(.rodata.cst4)
18 18 18 8 reloc
18 18 18 8 <internal>:(.rela.dyn)
30 30 18 8 .dynsym
30 30 18 8 <internal>:(.dynsym)
48 48 1c 8 .gnu.hash
48 48 1c 8 <internal>:(.gnu.hash)
64 64 10 4 .hash
64 64 10 4 <internal>:(.hash)
74 74 1 1 .dynstr
74 74 1 1 <internal>:(.dynstr)
78 78 e0 8 dynamic
78 78 e0 8 <internal>:(.dynamic)
0 0 48 1 .comment
0 0 48 1 <internal>:(.comment)
0 0 60 8 .symtab
0 0 60 8 <internal>:(.symtab)
0 0 57 1 .shstrtab
0 0 57 1 <internal>:(.shstrtab)
0 0 31 1 .strtab
0 0 31 1 <internal>:(.strtab)
And by inspecting the output binary, I can confirm that reloc
contains a single R_X86_64_RELATIVE
entry that makes TEST
point to .rodata.cst4
, which is expected.
But when building with cargo build --target aarch64-unknown-none --release
, the output map is:
VMA LMA Size Align Out In Symbol
0 0 14 8 data
0 0 10 8 D:\reloc-test\target\aarch64-unknown-none\release\deps\reloc_test-4ee72db71c31bd12.reloc_test.7a922d489d1080d8-cgu.0.rcgu.o:(.TEST)
0 0 0 1 $d.2
0 0 10 1 TEST
10 10 4 1 <internal>:(.rodata.cst4)
0 0 48 1 .comment
0 0 48 1 <internal>:(.comment)
0 0 90 8 .symtab
0 0 90 8 <internal>:(.symtab)
0 0 29 1 .shstrtab
0 0 29 1 <internal>:(.shstrtab)
0 0 37 1 .strtab
0 0 37 1 <internal>:(.strtab)
The dynamic and relocation sections are simply not there. Is this expected or a bug? Is there any way to make the sections appear?