Index: test/tools/llvm-objcopy/ELF/globalize.test =================================================================== --- test/tools/llvm-objcopy/ELF/globalize.test +++ test/tools/llvm-objcopy/ELF/globalize.test @@ -6,6 +6,16 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --globalize-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo " Global # global" > %t-list.txt +# RUN: echo "Local" >> %t-list.txt +# RUN: echo "Weak" >> %t-list.txt +# RUN: echo "WeakUndef" >> %t-list.txt +# RUN: echo " # comment " >> %t-list.txt +# RUN: llvm-objcopy --regex --globalize-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 +# RUN: echo ".+ # .+ " > %t-list2.txt +# RUN: llvm-objcopy --regex --globalize-symbols %t-list2.txt %t %t5 +# RUN: cmp %t2 %t5 !ELF FileHeader: Index: test/tools/llvm-objcopy/ELF/localize.test =================================================================== --- test/tools/llvm-objcopy/ELF/localize.test +++ test/tools/llvm-objcopy/ELF/localize.test @@ -9,6 +9,18 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --localize-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo " Global # comment " > %t-list.txt +# RUN: echo "GlobalUndef" >> %t-list.txt +# RUN: echo "Local" >> %t-list.txt +# RUN: echo "Weak" >> %t-list.txt +# RUN: echo "GlobalCommon" >> %t-list.txt +# RUN: echo " # comment " >> %t-list.txt +# RUN: llvm-objcopy --localize-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 +# RUN: echo " .*al.* # Global + Local + GlobalCommon " > %t-list2.txt +# RUN: echo "Weak" >> %t-list2.txt +# RUN: llvm-objcopy --regex --localize-symbols %t-list2.txt %t %t5 +# RUN: cmp %t2 %t5 !ELF FileHeader: Index: test/tools/llvm-objcopy/ELF/strip-symbol.test =================================================================== --- test/tools/llvm-objcopy/ELF/strip-symbol.test +++ test/tools/llvm-objcopy/ELF/strip-symbol.test @@ -5,6 +5,14 @@ # RUN: cmp %t2 %t3 # RUN: llvm-strip --regex --strip-symbol '^b.*' -N bar %t -o %t4 # RUN: cmp %t3 %t4 +# RUN: echo " bar # bar" > %t-list.txt +# RUN: echo " baz # baz" >> %t-list.txt +# RUN: echo " # no symbol" >> %t-list.txt +# RUN: llvm-objcopy --strip-symbols %t-list.txt %t %t5 +# RUN: cmp %t3 %t5 +# RUN: echo "b.* # bar & baz" > %t-list2.txt +# RUN: llvm-objcopy --regex --strip-symbols %t-list2.txt %t %t6 +# RUN: cmp %t3 %t6 !ELF FileHeader: Index: test/tools/llvm-objcopy/ELF/weaken.test =================================================================== --- test/tools/llvm-objcopy/ELF/weaken.test +++ test/tools/llvm-objcopy/ELF/weaken.test @@ -3,6 +3,16 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --weaken-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo " Global # comment" > %t-list.txt +# RUN: echo "Local" >> %t-list.txt +# RUN: echo "Weak" >> %t-list.txt +# RUN: echo " # comment" >> %t-list.txt +# RUN: llvm-objcopy --weaken-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 +# RUN: echo ".*al # Global + Local == .*al" > %t-list2.txt +# RUN: echo "Weak # weak" >> %t-list2.txt +# RUN: llvm-objcopy --regex --weaken-symbols %t-list2.txt %t %t5 +# RUN: cmp %t2 %t5 !ELF FileHeader: Index: tools/llvm-objcopy/CopyConfig.cpp =================================================================== --- tools/llvm-objcopy/CopyConfig.cpp +++ tools/llvm-objcopy/CopyConfig.cpp @@ -225,9 +225,9 @@ return Iter->getValue(); } -static void addGlobalSymbolsFromFile(std::vector &Symbols, - BumpPtrAllocator &Alloc, - StringRef Filename, bool UseRegex) { +static void addSymbolsFromFile(std::vector &Symbols, + BumpPtrAllocator &Alloc, StringRef Filename, + bool UseRegex) { StringSaver Saver(Alloc); SmallVector Lines; auto BufOrErr = MemoryBuffer::getFile(Filename); @@ -413,17 +413,29 @@ InputArgs.hasArg(OBJCOPY_decompress_debug_sections); for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol)) Config.SymbolsToLocalize.emplace_back(Arg->getValue(), UseRegex); + for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbols)) + addSymbolsFromFile(Config.SymbolsToLocalize, DC.Alloc, Arg->getValue(), + UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbol)) Config.SymbolsToKeepGlobal.emplace_back(Arg->getValue(), UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbols)) - addGlobalSymbolsFromFile(Config.SymbolsToKeepGlobal, DC.Alloc, - Arg->getValue(), UseRegex); + addSymbolsFromFile(Config.SymbolsToKeepGlobal, DC.Alloc, Arg->getValue(), + UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbol)) Config.SymbolsToGlobalize.emplace_back(Arg->getValue(), UseRegex); + for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbols)) + addSymbolsFromFile(Config.SymbolsToGlobalize, DC.Alloc, Arg->getValue(), + UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbol)) Config.SymbolsToWeaken.emplace_back(Arg->getValue(), UseRegex); + for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbols)) + addSymbolsFromFile(Config.SymbolsToWeaken, DC.Alloc, Arg->getValue(), + UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_strip_symbol)) Config.SymbolsToRemove.emplace_back(Arg->getValue(), UseRegex); + for (auto Arg : InputArgs.filtered(OBJCOPY_strip_symbols)) + addSymbolsFromFile(Config.SymbolsToRemove, DC.Alloc, Arg->getValue(), + UseRegex); for (auto Arg : InputArgs.filtered(OBJCOPY_keep_symbol)) Config.SymbolsToKeep.emplace_back(Arg->getValue(), UseRegex); Index: tools/llvm-objcopy/ObjcopyOpts.td =================================================================== --- tools/llvm-objcopy/ObjcopyOpts.td +++ tools/llvm-objcopy/ObjcopyOpts.td @@ -124,10 +124,21 @@ "Mark all symbols that have hidden or internal visibility as local">; defm localize_symbol : Eq<"localize-symbol", "Mark as local">, MetaVarName<"symbol">; +defm localize_symbols + : Eq<"localize-symbols", + "Reads a list of symbols from and marks them local.">, + MetaVarName<"filename">; + def L : JoinedOrSeparate<["-"], "L">, Alias; defm globalize_symbol : Eq<"globalize-symbol", "Mark as global">, MetaVarName<"symbol">; + +defm globalize_symbols + : Eq<"globalize-symbols", + "Reads a list of symbols from and marks them global.">, + MetaVarName<"filename">; + defm keep_global_symbol : Eq<"keep-global-symbol", "Convert all symbols except to local. May be repeated to " @@ -146,6 +157,11 @@ defm weaken_symbol : Eq<"weaken-symbol", "Mark as weak">, MetaVarName<"symbol">; +defm weaken_symbols + : Eq<"weaken-symbols", + "Reads a list of symbols from and marks them weak.">, + MetaVarName<"filename">; + def W : JoinedOrSeparate<["-"], "W">, Alias; def weaken : Flag<["-", "--"], "weaken">, HelpText<"Mark all global symbols as weak">; @@ -161,6 +177,11 @@ def x : Flag<["-"], "x">, Alias; defm strip_symbol : Eq<"strip-symbol", "Remove symbol ">, MetaVarName<"symbol">; +defm strip_symbols + : Eq<"strip-symbols", + "Reads a list of symbols from and removes them.">, + MetaVarName<"filename">; + def N : JoinedOrSeparate<["-"], "N">, Alias; defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol ">, MetaVarName<"symbol">;