[PATCH] D108985: [objcopy] Enable llvm options to be passed via $LLVM_OPTS
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 1 02:36:16 PDT 2021
sbc100 updated this revision to Diff 369891.
sbc100 added a comment.
- feedback
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108985/new/
https://reviews.llvm.org/D108985
Files:
llvm/test/tools/llvm-objcopy/llvm-options.test
llvm/tools/llvm-objcopy/llvm-objcopy.cpp
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -38,6 +38,7 @@
#include "llvm/Option/Option.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
@@ -63,6 +64,8 @@
using namespace llvm::objcopy;
using namespace llvm::object;
+#define DEBUG_TYPE "objcopy"
+
// The name this program was invoked as.
static StringRef ToolName;
@@ -86,14 +89,20 @@
(I + Tool.size() == Stem.size() || !isAlnum(Stem[I + Tool.size()]));
};
- if (Is("bitcode-strip") || Is("bitcode_strip"))
+ if (Is("bitcode-strip") || Is("bitcode_strip")) {
+ LLVM_DEBUG(llvm::dbgs() << "running as bitcode-strip\n");
return parseBitcodeStripOptions(Args);
- else if (Is("strip"))
+ }
+ if (Is("strip")) {
+ LLVM_DEBUG(llvm::dbgs() << "running as strip\n");
return parseStripOptions(Args, reportWarning);
- else if (Is("install-name-tool") || Is("install_name_tool"))
+ }
+ if (Is("install-name-tool") || Is("install_name_tool")) {
+ LLVM_DEBUG(llvm::dbgs() << "running as install-name-tool\n");
return parseInstallNameToolOptions(Args);
- else
- return parseObjcopyOptions(Args, reportWarning);
+ }
+ LLVM_DEBUG(llvm::dbgs() << "running as objcopy\n");
+ return parseObjcopyOptions(Args, reportWarning);
}
// For regular archives this function simply calls llvm::writeArchive,
@@ -417,6 +426,10 @@
? cl::TokenizeWindowsCommandLine
: cl::TokenizeGNUCommandLine,
NewArgv);
+ // Allow llvm options to be passed via $LLVM_INTERNAL_OPTS. This is useful
+ // for enabling common flags such as -debug.
+ cl::ParseCommandLineOptions(1, argv, "llvm-objcopy", nullptr,
+ "LLVM_INTERNAL_OPTS");
auto Args = makeArrayRef(NewArgv).drop_front();
Expected<DriverConfig> DriverConfig = getDriverConfig(Args);
Index: llvm/test/tools/llvm-objcopy/llvm-options.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/llvm-options.test
@@ -0,0 +1,8 @@
+# Verify that internal llvm options (such as `-debug`) can be injected via
+# the LLVM_INTERNAL_OPTS environment variable.
+
+RUN: llvm-objcopy --version 2>&1 | FileCheck %s
+RUN: env LLVM_INTERNAL_OPTS=-debug llvm-objcopy --version 2>&1 | FileCheck --check-prefix=DEBUG %s
+
+CHECK-NOT: running as
+DEBUG: running as objcopy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108985.369891.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210901/0cdf702a/attachment.bin>
More information about the llvm-commits
mailing list