diff options
-rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
-rw-r--r-- | lld/test/ELF/user_def_init_array_start.s | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 8d922291a8b..2ba08f7995f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1104,8 +1104,11 @@ template <class ELFT> static Symbol *addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name, OutputSectionBase<ELFT> *Sec, typename ELFT::uint Val) { - if (!Table.find(Name)) + SymbolBody *S = Table.find(Name); + if (!S) return nullptr; + if (!S->isUndefined() && !S->isShared()) + return S->symbol(); return Table.addSynthetic(Name, Sec, Val); } diff --git a/lld/test/ELF/user_def_init_array_start.s b/lld/test/ELF/user_def_init_array_start.s new file mode 100644 index 00000000000..6c33166d1d4 --- /dev/null +++ b/lld/test/ELF/user_def_init_array_start.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +// RUN: ld.lld %t.o -o %t2.so -shared +// Allow user defined __init_array_start. This is used by musl because of the +// the bfd linker not handling these properly. We always create them as +// hidden, musl should not have problems with lld. + + .hidden __init_array_start + .globl __init_array_start +__init_array_start: + .zero 8 |