[llvm] r331070 - [llvm-objcopy] Add --weaken-symbol (-W) option
Paul Semel via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 27 12:16:27 PDT 2018
Author: paulsemel
Date: Fri Apr 27 12:16:27 2018
New Revision: 331070
URL: http://llvm.org/viewvc/llvm-project?rev=331070&view=rev
Log:
[llvm-objcopy] Add --weaken-symbol (-W) option
Added:
llvm/trunk/test/tools/llvm-objcopy/weaken.test
Modified:
llvm/trunk/tools/llvm-objcopy/Opts.td
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
Added: llvm/trunk/test/tools/llvm-objcopy/weaken.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/weaken.test?rev=331070&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/weaken.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/weaken.test Fri Apr 27 12:16:27 2018
@@ -0,0 +1,75 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy --weaken-symbol Global -W Local -W Weak %t %t2
+# RUN: llvm-readobj -symbols %t2 | FileCheck %s
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x1000
+ AddressAlign: 0x0000000000000010
+ Size: 64
+Symbols:
+ Local:
+ - Name: Local
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x1000
+ Size: 8
+ Weak:
+ - Name: Weak
+ Type: STT_FUNC
+ Size: 8
+ Section: .text
+ Value: 0x1008
+ Global:
+ - Name: Global
+ Type: STT_FUNC
+ Size: 8
+ Section: .text
+ Value: 0x1010
+
+#CHECK: Symbols [
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name:
+#CHECK-NEXT: Value: 0x0
+#CHECK-NEXT: Size: 0
+#CHECK-NEXT: Binding: Local
+#CHECK-NEXT: Type: None
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: Undefined
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: Local
+#CHECK-NEXT: Value: 0x1000
+#CHECK-NEXT: Size: 8
+#CHECK-NEXT: Binding: Local
+#CHECK-NEXT: Type: Function
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: Global
+#CHECK-NEXT: Value: 0x1010
+#CHECK-NEXT: Size: 8
+#CHECK-NEXT: Binding: Weak
+#CHECK-NEXT: Type: Function
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: Weak
+#CHECK-NEXT: Value: 0x1008
+#CHECK-NEXT: Size: 8
+#CHECK-NEXT: Binding: Weak
+#CHECK-NEXT: Type: Function
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
+#CHECK-NEXT:]
Modified: llvm/trunk/tools/llvm-objcopy/Opts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Opts.td?rev=331070&r1=331069&r2=331070&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Opts.td (original)
+++ llvm/trunk/tools/llvm-objcopy/Opts.td Fri Apr 27 12:16:27 2018
@@ -67,3 +67,8 @@ def L : JoinedOrSeparate<["-"], "L">,
defm globalize_symbol : Eq<"globalize-symbol">,
MetaVarName<"symbol">,
HelpText<"Mark <symbol> as global">;
+defm weaken_symbol : Eq<"weaken-symbol">,
+ MetaVarName<"symbol">,
+ HelpText<"Mark <symbol> as weak">;
+def W : JoinedOrSeparate<["-"], "W">,
+ Alias<weaken_symbol>;
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=331070&r1=331069&r2=331070&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Fri Apr 27 12:16:27 2018
@@ -120,6 +120,7 @@ struct CopyConfig {
std::vector<StringRef> AddSection;
std::vector<StringRef> SymbolsToLocalize;
std::vector<StringRef> SymbolsToGlobalize;
+ std::vector<StringRef> SymbolsToWeaken;
StringMap<StringRef> SymbolsToRename;
bool StripAll;
bool StripAllGNU;
@@ -328,6 +329,11 @@ void HandleArgs(const CopyConfig &Config
is_contained(Config.SymbolsToGlobalize, Sym.Name))
Sym.Binding = STB_GLOBAL;
+ if (!Config.SymbolsToWeaken.empty() &&
+ is_contained(Config.SymbolsToWeaken, Sym.Name) &&
+ Sym.Binding == STB_GLOBAL)
+ Sym.Binding = STB_WEAK;
+
const auto I = Config.SymbolsToRename.find(Sym.Name);
if (I != Config.SymbolsToRename.end())
Sym.Name = I->getValue();
@@ -421,6 +427,8 @@ CopyConfig ParseObjcopyOptions(ArrayRef<
Config.SymbolsToLocalize.push_back(Arg->getValue());
for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbol))
Config.SymbolsToGlobalize.push_back(Arg->getValue());
+ for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbol))
+ Config.SymbolsToWeaken.push_back(Arg->getValue());
return Config;
}
More information about the llvm-commits
mailing list