[PATCH] D17918: [ELF] - Issue an error if trying to generate relocatable from objects having mixed splitstacks.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 6 16:37:04 PST 2016


ruiu added a comment.

This patch covers a tricky use case. Is this actually needed? I mean if you want to do something for the split stack, why don't you support it in the linker instead of rejecting it?

Even if you want reject it, this patch seems a bit too much. There is a simpler way of doing the same thing. InputFiles and Sections can be agnostic of the split stack. Instead, it can be done using a few non-member function as shown below.

  template <class ELFT>
  static bool hasSplitStack(const std::unique_ptr<ObjectFile<ELFT>> &File) {
    for (InputSectionBase<ELFT> *Sec : File->getSections())
      if (auto *S = dyn_cast_or_null<InputSection<ELFT>>(Sec))
        if (S->getSectionName() == ".note.GNU-split-stack")
          return true;
    return false;
  }
  
  template <class ELFT>
  static void checkSplitSections(SymbolTable<ELFT> &Symtab) {
    if (!Config->Relocatable)
      return;
    const std::vector<std::unique_ptr<ObjectFile<ELFT>>> &Files
        = Symtab.getObjectFiles();
    bool HasSplitStack = hasSplitStack<ELFT>(Files.front());
    auto Fn = [=](const std::unique_ptr<ObjectFile<ELFT>> &Obj) {
      return hasSplitStack<ELFT>(Obj) == HasSplitStack;
    };
    if (!std::all_of(Files.begin(), Files.end(), Fn))
      error("You cannot mix object files compiled with -fsplit-stack"
            " and -fno-split-stack");
  }

(I'm not arguing that this is what I want because I'm not sure if this feature should be in, but if it is, it can be simplified.)


http://reviews.llvm.org/D17918





More information about the llvm-commits mailing list