[PATCH] D27613: [ELF] - Change now -Ttext/-Tdata/-Tbss works.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 9 13:43:14 PST 2016
> +## Check that user can assing addressed for sections using -T option.
> +# RUN: ld.lld -Ttext 0x0 -Tdata 0x2000 -Tbss 0x4000 %t -o %t1
> +# RUN: llvm-objdump -section-headers %t1 | FileCheck %s --check-prefix=USERADDR
> +# USERADDR: Sections:
> +# USERADDR-NEXT: Idx Name Size Address Type
> +# USERADDR-NEXT: 0 00000000 0000000000000000
> +# USERADDR-NEXT: 1 .text 00000001 0000000000000000 TEXT DATA
> +# USERADDR-NEXT: 2 .rodata 00000008 0000000000000001 DATA
The address of .rodata is not set, should it be here instead of after .bss?
> +# USERADDR-NEXT: 3 .data 00000008 0000000000002000 DATA
> +# USERADDR-NEXT: 4 .aw 00000008 0000000000002008 DATA
> +# USERADDR-NEXT: 5 .bss 00000008 0000000000004000 BSS
> +template <class ELFT> static uint64_t getVABase() {
> + if (Config->SectionStartMap.empty())
> + return Config->ImageBase;
> +
> + uint64_t VA = (uint64_t)-1;
> + for (auto I = Config->SectionStartMap.begin();
> + I != Config->SectionStartMap.end(); ++I) {
> + if (VA > I->second)
> + VA = I->second;
> + }
> + uint64_t HeadersSize = getHeaderSize<ELFT>();
> + if (VA > HeadersSize)
> + return VA - HeadersSize;
> + return VA;
> +}
You should be able to do this computation once and store it in
Config->ImageBase, no?
> // If two sections share the same PT_LOAD the file offset is calculated
> // using this formula: Off2 = Off1 + (VA2 - VA1).
> - return First->Offset + Sec->Addr - First->Addr;
> + // We take max value here for case when user set VA of section using -T
> + // below address of headers. We do not align offsets then, that is
> + // consistent with bfd behavior.
> + return std::max<uintX_t>(Off, First->Offset + Sec->Addr - First->Addr);
This seems wrong. If both sections are in the same PT_LOAD, the
difference from address and offsets are set in stone.
Cheers,
Rafael
More information about the llvm-commits
mailing list