Hi all,
When porting a project from using GNU-gcc to LLVM with LLD I encounter
this discrepancy in the `__tbss_end` symbol.
With an explicit linker script, the __tbss_end symbols has the same
value as __tbss_start:
.tbss :
{
__tbss_start = .;
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
__tbss_end = .;
}
LD correctly assigns the end to __tbss_end. We need to determine the
size of the tbss section to initialize it on our bare-metal target.
What is the proper way to determine the tbss section size in LLD?
Noah
Why don't you use the program header for that?
Joerg
We have a bare-metal target and the ELF contains the crt0 that
initializes the tls region so we need to know the tbss size at link
time. Exactly as for a regular bss section, we need sbss and ebss at
link time for our loader to initialize this section
I don't understand what you are trying to say. The PT_TLS segment will
tell you exactly where the TLS block is and what size should be
allocated for the per thread data. That's also normally something the
runtime is doing and not the loader, simply because it is part of the
thread creation logic.
Joerg
The incorrect dot is related to ThreadBssOffset.
When location counter was implemented (during
⚙ D18499 [ELF] - Implemented basic location counter support. and rL282147 time), ThreadBssOffset was
added to support multiple tbss sections.
This has limited support in ld.lld and isn't supported by GNU ld.
I sent ⚙ D107208 [ELF] Make dot in .tbss correct to make __tbss_end = .; work.
Happy to back port it into 13.0.0
The incorrect dot is related to ThreadBssOffset.
When location counter was implemented (during
⚙ D18499 [ELF] - Implemented basic location counter support. and rL282147 time), ThreadBssOffset was
added to support multiple tbss sections.
This has limited support in ld.lld and isn't supported by GNU ld.
I sent ⚙ D107208 [ELF] Make dot in .tbss correct to make __tbss_end = .; work.
Happy to back port it into 13.0.0
That is exactly what solved my problem, thanks! Happy to see this in 13.0.0.
@Joerg We (mis)use the TLS section for hardware threads in a cluster of
RISCV cores that executes a statically linked binary. The TLS allocation
is done by each hart at boot. The cluster doesn't have access to the ELF
but copies (t)data to its local memory. We don't have a loader nor
thread creation logic in that regard.
Fixed in main (⚙ D107208 [ELF] Make dot in .tbss correct) and cherry picked
into release/13.x