From 0334578edc60ad8a7455e7b76e41901376245b56 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 8 Aug 2020 18:17:38 -0700 Subject: [PATCH] [ELF] --wrap: don't leave the original symbol as SHN_UNDEF in .symtab or .dynsym --- lld/ELF/SymbolTable.cpp | 2 ++ lld/test/ELF/wrap-shlib-undefined.s | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index afc8b05..6283d94 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -42,6 +42,8 @@ void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { if (real->exportDynamic) sym->exportDynamic = true; + if (sym->isUndefined()) + sym->isUsedInRegularObj = false; // Now renaming is complete, and no one refers to real. We drop real from // .symtab and .dynsym. If real is undefined, it is important that we don't diff --git a/lld/test/ELF/wrap-shlib-undefined.s b/lld/test/ELF/wrap-shlib-undefined.s index 175f2ec..eca21b9 100644 --- a/lld/test/ELF/wrap-shlib-undefined.s +++ b/lld/test/ELF/wrap-shlib-undefined.s @@ -26,10 +26,8 @@ # RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=DYNSYM # RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=ASM -## FIXME GNU ld does not export bar -# DYNSYM: Symbol table '.dynsym' contains 3 entries: +# DYNSYM: Symbol table '.dynsym' contains 2 entries: # DYNSYM: NOTYPE LOCAL DEFAULT UND -# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND bar # DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar # ASM: <_start>: -- 2.7.4