[PATCH] D27613: [ELF] - Change how -Ttext/-Tdata/-Tbss works.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 01:06:23 PST 2016
>>> + // When user gives -Ttext/-Tdata/-Tbss GNU linkers either set addresses
>>> + // of corresponding sections or addressed for PT_LOADs. That means we want
>>> + // to have "text segment" to work with. It includes RO sections as well.
>>> + if (!Config->SectionStartMap.empty())
>>> + Config->SingleRoRx = true;
>>
>> Not sure I understand the comment. Maybe just say that some programs
>> using -TText expect to also see the ro section in the selected address?
>
>This looks to be independent from the rest of the patch and should be in
>a followup if needed.
Since I was trying to fix pr31295, reproduce had .rodata, so I included this in the patch.
It is possible to make this in a following patch I think.
>>
>>> // Parses -image-base option.
>>> static uint64_t getImageBase(opt::InputArgList &Args) {
>>> + // When -T<section> option is specified, lowest VA value
>>> + // becomes the image base address.
>>> + if (!Config->SectionStartMap.empty()) {
>>> + uint64_t VA = (uint64_t)-1;
>>> + for (auto I = Config->SectionStartMap.begin();
>>> + I != Config->SectionStartMap.end(); ++I) {
>>> + if (VA > I->second)
>>> + VA = I->second;
>>> + }
>>> + return VA;
>>> + }
>>
>> If that is higher than the default base we probably want to use the
>> default, no?
>
>The situation is actually quite a bit more complicated. If we want to
>fully support putting a section at a given address, what we have to do
>is
>
>* Find the minimum address requested for any section.
>* See if the headers would fit in that, if so, subtract the header
> size. If not, remember that we are not allocating the headers.
>* If the computed value is less than the image base, adjust the image
> base.
I tried to minimize the patch. PR reveals users with -Ttext=0x0 and 0x2000,
both are below ImageBase, so I decided not to overcomplicate patch with this logic of
adjusting ImageBase.
It is not really clear for me what is "we are not allocating the headers", as
I am able to readelf bfd output (from 31295 attachment), so output is not just a binary blob.
George.
More information about the llvm-commits
mailing list