[PATCH] D27200: [ELF] - Do not create 4gb output when -obinary -Ttext and -omagic used together.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 29 23:35:29 PST 2016


grimar added a comment.

In https://reviews.llvm.org/D27200#607902, @ruiu wrote:

> The way how this patch fixes the issue is a bit puzzling and too subtle (the important condition is buried inside createPhdrs which later affects file offset computation in an nonobvious). I believe there's a better way. Let me take a closer look.


The fact we are setting offsets basing on First section in a load actually does not seems too subtle for me:

  static uintX_t getFileAlignment(uintX_t Off, OutputSectionBase *Sec) {
  ...
    return First->Offset + Sec->Addr - First->Addr;

-Ttext in this case sets address of .text below the 0x10000 what is ImageBase (to 0x600). 
We set image base address to headers:

  uintX_t BaseVA = Config->ImageBase;
  Out<ELFT>::ElfHeader->Addr = BaseVA;
  Out<ELFT>::ProgramHeaders->Addr = BaseVA + Out<ELFT>::ElfHeader->Size;

one of solutions probably could be set some different BaseVA here in that case (0x600 - X),
but I found that much more puzling and wrong to rely on headers addresses for offsets for binary output,
since they should absent and even PT_LOAD can be excessive and probably also should not be created (like this patch do).


https://reviews.llvm.org/D27200





More information about the llvm-commits mailing list