[llvm] r339362 - [llvm-objcopy] Add --prefix-symbols option
Paul Semel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 9 10:49:04 PDT 2018
Author: paulsemel
Date: Thu Aug 9 10:49:04 2018
New Revision: 339362
URL: http://llvm.org/viewvc/llvm-project?rev=339362&view=rev
Log:
[llvm-objcopy] Add --prefix-symbols option
Differential Revision: https://reviews.llvm.org/D50381
Added:
llvm/trunk/test/tools/llvm-objcopy/prefix-symbols.test
Modified:
llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
llvm/trunk/tools/llvm-objcopy/Object.h
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
Added: llvm/trunk/test/tools/llvm-objcopy/prefix-symbols.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/prefix-symbols.test?rev=339362&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/prefix-symbols.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/prefix-symbols.test Thu Aug 9 10:49:04 2018
@@ -0,0 +1,71 @@
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objcopy --prefix-symbols prefix %t %t2
+# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=COMMON --check-prefix=BASIC
+# RUN: llvm-objcopy --redefine-sym bar=baz --prefix-symbols prefix %t %t3
+# RUN: llvm-readobj -symbols %t3 | FileCheck %s --check-prefix=COMMON --check-prefix=REDEF
+
+!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: foo
+ Type: STT_SECTION
+ Section: .text
+ - Name: bar
+ Type: STT_FILE
+ Section: .text
+ Global:
+ - Name: foobar
+ Type: STT_FUNC
+ Section: .text
+
+# COMMON: Symbols [
+# COMMON-NEXT: Symbol {
+# COMMON-NEXT: Name:
+# COMMON-NEXT: Value: 0x0
+# COMMON-NEXT: Size: 0
+# COMMON-NEXT: Binding: Local
+# COMMON-NEXT: Type: None
+# COMMON-NEXT: Other: 0
+# COMMON-NEXT: Section: Undefined
+# COMMON-NEXT: }
+# COMMON-NEXT: Symbol {
+# COMMON-NEXT: Name: foo
+# COMMON-NEXT: Value: 0x0
+# COMMON-NEXT: Size: 0
+# COMMON-NEXT: Binding: Local
+# COMMON-NEXT: Type: Section
+# COMMON-NEXT: Other: 0
+# COMMON-NEXT: Section: .text
+# COMMON-NEXT: }
+# COMMON-NEXT: Symbol {
+# BASIC-NEXT: Name: prefixbar
+# REDEF-NEXT: Name: prefixbaz
+# COMMON-NEXT: Value: 0x0
+# COMMON-NEXT: Size: 0
+# COMMON-NEXT: Binding: Local
+# COMMON-NEXT: Type: File
+# COMMON-NEXT: Other: 0
+# COMMON-NEXT: Section: .text
+# COMMON-NEXT: }
+# COMMON-NEXT: Symbol {
+# COMMON-NEXT: Name: prefixfoobar
+# COMMON-NEXT: Value: 0x0
+# COMMON-NEXT: Size: 0
+# COMMON-NEXT: Binding: Global
+# COMMON-NEXT: Type: Function
+# COMMON-NEXT: Other: 0
+# COMMON-NEXT: Section: .text
+# COMMON-NEXT: }
+# COMMON-NEXT:]
Modified: llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td?rev=339362&r1=339361&r2=339362&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td (original)
+++ llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td Thu Aug 9 10:49:04 2018
@@ -105,3 +105,6 @@ def keep_file_symbols : Flag<["-", "--"]
defm dump_section : Eq<"dump-section">,
MetaVarName<"section=file">,
HelpText<"Dump contents of section named <section> into file <file>">;
+defm prefix_symbols : Eq<"prefix-symbols">,
+ MetaVarName<"prefix">,
+ HelpText<"Add <prefix> to the start of every symbol name">;
Modified: llvm/trunk/tools/llvm-objcopy/Object.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.h?rev=339362&r1=339361&r2=339362&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.h (original)
+++ llvm/trunk/tools/llvm-objcopy/Object.h Thu Aug 9 10:49:04 2018
@@ -387,7 +387,7 @@ struct Symbol {
SectionBase *DefinedIn = nullptr;
SymbolShndxType ShndxType;
uint32_t Index;
- StringRef Name;
+ std::string Name;
uint32_t NameIndex;
uint64_t Size;
uint8_t Type;
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=339362&r1=339361&r2=339362&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Thu Aug 9 10:49:04 2018
@@ -133,6 +133,7 @@ struct CopyConfig {
StringRef SplitDWO;
StringRef AddGnuDebugLink;
+ StringRef SymbolsPrefix;
std::vector<StringRef> ToRemove;
std::vector<StringRef> Keep;
std::vector<StringRef> OnlyKeep;
@@ -388,6 +389,9 @@ static void HandleArgs(const CopyConfig
const auto I = Config.SymbolsToRename.find(Sym.Name);
if (I != Config.SymbolsToRename.end())
Sym.Name = I->getValue();
+
+ if (!Config.SymbolsPrefix.empty() && Sym.Type != STT_SECTION)
+ Sym.Name = (Config.SymbolsPrefix + Sym.Name).str();
});
// The purpose of this loop is to mark symbols referenced by sections
@@ -723,6 +727,7 @@ static CopyConfig ParseObjcopyOptions(Ar
Config.SplitDWO = InputArgs.getLastArgValue(OBJCOPY_split_dwo);
Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
+ Config.SymbolsPrefix = InputArgs.getLastArgValue(OBJCOPY_prefix_symbols);
for (auto Arg : InputArgs.filtered(OBJCOPY_redefine_symbol)) {
if (!StringRef(Arg->getValue()).contains('='))
More information about the llvm-commits
mailing list