mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[llvm-objcopy] Add --weaken-symbol (-W) option
llvm-svn: 331070
This commit is contained in:
parent
4f7c52eb8c
commit
9f7c96bb7c
75
test/tools/llvm-objcopy/weaken.test
Normal file
75
test/tools/llvm-objcopy/weaken.test
Normal file
@ -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:]
|
@ -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>;
|
||||
|
@ -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, Object &Obj, const Reader &Reader,
|
||||
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<const char *> ArgsArr) {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user