This patch implements LOADADDR() linkerscript function and ability to fetch LMA for section.
Details
Diff Detail
Event Timeline
ELF/LinkerScript.cpp | ||
---|---|---|
429 | Do you need to set an LMA to sections without AT command? | |
ELF/LinkerScript.h | ||
175 | LMA is fine with me as we write VA instead of Va, so please rename this function. | |
ELF/Writer.cpp | ||
949 | What is b in bHasLma? | |
993–995 | Why do we have to create a new segment if there's a section with a LMA? |
ELF/Writer.cpp | ||
---|---|---|
993–994 | You can write this as: bHasLma |= Script<ELFT>::X->hasLma(Sec->getName()) |
ELF/LinkerScript.cpp | ||
---|---|---|
429 | Yes, because LMA and VMA might not be the same, even if there is no AT command for a section. See summary for this patch | |
ELF/Writer.cpp | ||
993–995 | There is no straight way to get LMA for section from section header. The header field sh_addr is VMA, not LMA. However tools like objdump and objcopy still can fetch LMA. They are doing this by examining segment table and fetching segment physical address in case segment virtual address matches section VMA. This means that if section LMA doesn't match VMA, it should have separate load segment in order to properly calculate LMA for them. |
Diff updated. It turned out, that binutils can fetch LMA for section even if it doesn't start PT_LOAD segment, so
this patch can be simplified.
Sample of use from the wild:
https://searchcode.com/file/51551302/arch/x86_64/kernel/vmlinux.lds.S
test/ELF/linkerscript/loadaddr.s | ||
---|---|---|
15 | You probably want to check LOADADDR(xxx), where xxx - section that does not exist. |
test/ELF/linkerscript/loadaddr.s | ||
---|---|---|
15 | Unfortunately this will not work, because empty sections are not fully supported: empty sections which don't contain symbols are simply ignored. I'm making a patch which addresses this problem. |
test/ELF/linkerscript/loadaddr.s | ||
---|---|---|
15 | I was mean something like I did in my version of that: D24910 ## Check that we error out if trying to get load address of ## section that does not exist. # RUN: echo "SECTIONS { .bar LOADADDR(.zed) : { *(.bar*) } }" > %t.script # RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 \ # RUN: | FileCheck -check-prefix=ERR %s # ERR: undefined section .zed So there is no .zed section and it is impossible to call LOADADDR(.zed) |
LMA is fine with me as we write VA instead of Va, so please rename this function.