[ELF] --wrap: don't unnecessarily expose __real_
authorFangrui Song <i@maskray.me>
Thu, 1 Oct 2020 03:09:25 +0000 (20:09 -0700)
committerFangrui Song <i@maskray.me>
Thu, 1 Oct 2020 03:09:25 +0000 (20:09 -0700)
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
lld/test/ELF/lto/wrap-1.ll

index 5e80385..fa39628 100644 (file)
@@ -1867,7 +1867,7 @@ static std::vector<WrappedSymbol> 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});
 
index 5ff4627..5355df2 100644 (file)
 ; 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"