From 4e9277eda1874ead60f2c9d7cdb558fd19b32076 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 30 Sep 2020 20:09:25 -0700 Subject: [PATCH] [ELF] --wrap: don't unnecessarily expose __real_ The routing rules are: sym -> __wrap_sym __real_sym -> sym __wrap_sym and sym are routing targets, so they need to be exposed to the symbol table. __real_sym is not and can be eliminated if not used by regular object. --- lld/ELF/Driver.cpp | 2 +- lld/test/ELF/lto/wrap-1.ll | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 5e80385..fa39628 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1867,7 +1867,7 @@ static std::vector addWrappedSymbols(opt::InputArgList &args) { if (!sym) continue; - Symbol *real = addUndefined(saver.save("__real_" + name)); + Symbol *real = addUnusedUndefined(saver.save("__real_" + name)); Symbol *wrap = addUnusedUndefined(saver.save("__wrap_" + name)); v.push_back({sym, real, wrap}); diff --git a/lld/test/ELF/lto/wrap-1.ll b/lld/test/ELF/lto/wrap-1.ll index 5ff4627..5355df2 100644 --- a/lld/test/ELF/lto/wrap-1.ll +++ b/lld/test/ELF/lto/wrap-1.ll @@ -17,11 +17,12 @@ ; CHECK-NEXT: Binding: Global ; CHECK-NEXT: Type: Function -; Make sure that the 'r' (linker redefined) bit is set for bar and __wrap_bar -; in the resolutions file. -; RESOLS: ,bar,xr -; RESOLS: ,__wrap_bar,plx -; RESOLS: ,__real_bar,plxr +; Make sure that the 'r' (linker redefined) bit is set for bar and __real_bar +; in the resolutions file. The calls to bar and __real_bar will be routed to +; __wrap_bar and bar, respectively. So they cannot be inlined. +; RESOLS: ,bar,xr{{$}} +; RESOLS: ,__wrap_bar,plx{{$}} +; RESOLS: ,__real_bar,plr{{$}} target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" -- 2.7.4