[PATCH] D27613: [ELF] - Change now -Ttext/-Tdata/-Tbss works.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 10:09:57 PST 2016


George Rimar <grimar at accesssoftek.com> writes:
>>>    // 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.
>
> That is not what bfd do. Problem is that First here is a elf header. Imagine we have
> -Ttext=0x0.
>
> And Sec is .text then.
> That way First->Offset == 0x0, First->Addr == 0x0 and Sec->Addr == 0x0.
>
> bfd just ignores file offsets aligning and I supposed we can do the same since that is feature
> for loaders and they work with bfd. 

Having the offsets match the address in the same PT_LOAD is a physical
requirement. It is just not possible for them to be different as each
PT_LOAD is a mmap.

>From the description I would guess that bfd just doesn't add the header
to a PT_LOAD if there is not enough space.

Cheers,
Rafael


More information about the llvm-commits mailing list