[PATCH] D18357: [LTO] Include in .symtab/.dynsym symbols introduced by optimizations

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 13:15:30 PDT 2016


I think this is fine with a test, but please upload a version that includes one.


On 22 March 2016 at 12:54, Davide Italiano <dccitaliano at gmail.com> wrote:
> davide created this revision.
> davide added reviewers: rafael, joker.eph.
> davide added a subscriber: llvm-commits.
> Herald added a subscriber: joker.eph.
>
> Some optimizations, e.g. SimplifyLibCalls, can replace functions with others as part of the lowering, e.g. printf => puts.
> The new symbols don't have the isUsedInRegularObj flag set so they don't get included in the final symbol table (and dynamic symbol table), and the dynamic linker gets confused.
>
> davide at foogoo:~/llvm/build/bin % ./clang blah.c -o blah -flto -fuse-ld=lld -Wl,-L/lib
> davide at foogoo:~/llvm/build/bin % ./blah
> Segmentation fault (core dumped)
> davide at foogoo:~/llvm/build/bin % ./llvm-nm ./blah | grep puts
>
> % cat blah.c
> #include <stdio.h>
>
> int main(void)
> {
>   printf("blah\n");
>   return (0);
> }
>
> My proposed fix is to set the flag in addCombinedLtoObject() once we see the new symbols. I'm working on a testcase now, but I would like to hear if this sounds reasonable to you.
>
> http://reviews.llvm.org/D18357
>
> Files:
>   ELF/SymbolTable.cpp
>   ELF/Symbols.h
>
> Index: ELF/Symbols.h
> ===================================================================
> --- ELF/Symbols.h
> +++ ELF/Symbols.h
> @@ -73,6 +73,7 @@
>    bool isShared() const { return SymbolKind == SharedKind; }
>    bool isLocal() const { return IsLocal; }
>    bool isUsedInRegularObj() const { return IsUsedInRegularObj; }
> +  void setUsedInRegularObj() { IsUsedInRegularObj = true; }
>    bool isPreemptible() const;
>    template <class ELFT> bool isGnuIfunc() const;
>
> @@ -317,7 +318,6 @@
>    std::unique_ptr<InputFile> getMember();
>
>    void setWeak() { IsWeak = true; }
> -  void setUsedInRegularObj() { IsUsedInRegularObj = true; }
>
>  private:
>    ArchiveFile *File;
> Index: ELF/SymbolTable.cpp
> ===================================================================
> --- ELF/SymbolTable.cpp
> +++ ELF/SymbolTable.cpp
> @@ -229,8 +229,10 @@
>    Obj->parse(DummyGroups);
>    for (SymbolBody *Body : Obj->getNonLocalSymbols()) {
>      Symbol *Sym = insert(Body);
> -    if (!Sym->Body->isUndefined() && Body->isUndefined())
> +    if (!Sym->Body->isUndefined() && Body->isUndefined()) {
> +      Sym->Body->setUsedInRegularObj();
>        continue;
> +    }
>      Sym->Body = Body;
>    }
>  }
>
>


More information about the llvm-commits mailing list