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,10 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --globalize-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo "Local # local" > %t-list.txt +# RUN: echo "Weak.* # weak" >> %t-list.txt +# RUN: llvm-objcopy --regex --globalize-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 !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,11 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --localize-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo " Global.* " > %t-list.txt +# RUN: echo "Local" >> %t-list.txt +# RUN: echo "Weak" >> %t-list.txt +# RUN: llvm-objcopy --regex --localize-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 !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,10 @@ # RUN: cmp %t2 %t3 # RUN: llvm-strip --regex --strip-symbol '^b.*' -N bar %t -o %t4 # RUN: cmp %t3 %t4 +# RUN: echo "b.*" > %t-list.txt +# RUN: echo " # empty symbol name with comment" >> %t-list.txt +# RUN: llvm-objcopy --regex --strip-symbols %t-list.txt %t %t5 +# RUN: cmp %t3 %t5 !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,11 @@ # RUN: llvm-readobj --symbols %t2 | FileCheck %s # RUN: llvm-objcopy --regex --weaken-symbol='.*' %t %t3 # RUN: cmp %t2 %t3 +# RUN: echo "Global" > %t-list.txt +# RUN: echo "Local" >> %t-list.txt +# RUN: echo "Weak" >> %t-list.txt +# RUN: llvm-objcopy --weaken-symbols %t-list.txt %t %t4 +# RUN: cmp %t2 %t4 !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">;