From 99c8fa3bef04901f34e8bdb1d2b5261a99a648a9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 2 May 2017 05:07:41 +0000 Subject: [PATCH] ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO. If there is a bug in the LTO implementation that causes it to fail to provide an expected symbol definition, the linker should report an undefined symbol error. Unfortunately, we were failing to do so if the symbol definition was weak, as the undefine() function was turning the definition into a weak undefined symbol, which resolves to zero if the symbol remains undefined. This patch causes us to set the binding to STB_GLOBAL when we undefine a symbol. I can't see a good way to test this. The behaviour should only be observable if there is a bug in the LTO implementation. Differential Revision: https://reviews.llvm.org/D32731 llvm-svn: 301897 --- lld/ELF/LTO.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index dd43517..de0d45b 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -105,6 +105,11 @@ BitcodeCompiler::~BitcodeCompiler() = default; static void undefine(Symbol *S) { replaceBody(S, S->body()->getName(), /*IsLocal=*/false, STV_DEFAULT, S->body()->Type, nullptr); + // It shouldn't normally matter what the binding is, but if a bug in the LTO + // implementation causes it to fail to provide a definition for a symbol, + // setting the binding to STB_GLOBAL will cause the linker to report an + // undefined symbol error, even if the definition was weak. + S->Binding = STB_GLOBAL; } void BitcodeCompiler::add(BitcodeFile &F) { -- 2.7.4