summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
diff options
context:
space:
mode:
authorJake Ehrlich <jakehehrlich@google.com>2017-10-10 18:47:09 +0000
committerJake Ehrlich <jakehehrlich@google.com>2017-10-10 18:47:09 +0000
commit36a2eb34ed394b7277df6ef9b935bfe2be3402b8 (patch)
tree876ae8d0fd21d2494acbb401953c66431e5e7a64 /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parentc5ff72708d232079e1c2099165584cf8d03e1c7e (diff)
downloadbcm5719-llvm-36a2eb34ed394b7277df6ef9b935bfe2be3402b8.tar.gz
bcm5719-llvm-36a2eb34ed394b7277df6ef9b935bfe2be3402b8.zip
[llvm-objcopy] Add support for removing sections
This change adds support for removing sections using the -R field (as GNU objcopy does as well). This change should let us add many helpful tests and is a proper stepping stone for adding more general kinds of stripping. Differential Revision: https://reviews.llvm.org/D38260 llvm-svn: 315346
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 9b233951b8d..775c5ae42b6 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -56,17 +56,24 @@ cl::opt<std::string> OutputFilename(cl::Positional, cl::desc("<output>"),
cl::opt<std::string>
OutputFormat("O", cl::desc("set output format to one of the following:"
"\n\tbinary"));
+// TODO: make this a cl::list to support removing multiple sections
+cl::opt<std::string> ToRemove("remove-section",
+ cl::desc("Remove a specific section"));
+cl::alias ToRemoveA("R", cl::desc("Alias for remove-section"), cl::aliasopt(ToRemove));
void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
std::unique_ptr<FileOutputBuffer> Buffer;
std::unique_ptr<Object<ELF64LE>> Obj;
if (!OutputFormat.empty() && OutputFormat != "binary")
error("invalid output format '" + OutputFormat + "'");
-
if (!OutputFormat.empty() && OutputFormat == "binary")
Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile);
else
Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile);
+ if (!ToRemove.empty()) {
+ Obj->removeSections(
+ [&](const SectionBase &Sec) { return ToRemove == Sec.Name; });
+ }
Obj->finalize();
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(OutputFilename, Obj->totalSize(),
OpenPOWER on IntegriCloud