[PATCH] D55423: [LLD][ELF] - A fix for "linker script assignment loses relative nature of section" bug.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 7 06:10:17 PST 2018


grimar added a comment.

In D55423#1323012 <https://reviews.llvm.org/D55423#1323012>, @peter.smith wrote:

> One thing I haven't checked through yet is whether there is a more specific check for a relocation to an absolute address. Ideally we wouldn't want to allow a relative relocation to symbol = 0x1000 but we would symbol = some_other_symbol. I don't know whether that is possible though given the context available at the time. Letting it through is probably the best option (rely on the user knowing what they are doing).


I agree. In theory, we could do some additional fixup of the symbols values before scanning the relocations, it would allow distinguishing between non-absolute and absolute symbols,
that is what I also tried when experimented with the code for this patch, it was:

  void LinkerScript::assignSymbolSections() {
    for (BaseCommand *Base : Script->SectionCommands) {
      auto *Cmd = dyn_cast<SymbolAssignment>(Base);
      if (!Cmd || !Cmd->Sym)
        continue;
  
      auto Deleter = make_unique<AddressState>();
      Ctx = Deleter.get();
      Ctx->OutSec = Aether;
  
      ExprValue V = Cmd->Expression();
      if (!V.isAbsolute())
        Cmd->Sym->Section = V.Sec;
    }
  }

But it is too complicated and this patch is much simpler without such things.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55423/new/

https://reviews.llvm.org/D55423





More information about the llvm-commits mailing list