[lld] r217650 - [mach-o] support "0x" or "0X" as prefix on hex numbers on command line

Nick Kledzik kledzik at apple.com
Thu Sep 11 17:16:29 PDT 2014


Author: kledzik
Date: Thu Sep 11 19:16:29 2014
New Revision: 217650

URL: http://llvm.org/viewvc/llvm-project?rev=217650&view=rev
Log:
[mach-o] support "0x" or "0X" as prefix on hex numbers on command line

This matches the strtoull() behavior in ld64.

Modified:
    lld/trunk/lib/Driver/DarwinLdDriver.cpp

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=217650&r1=217649&r2=217650&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Thu Sep 11 19:16:29 2014
@@ -167,6 +167,13 @@ std::error_code parseFileList(StringRef
   return std::error_code();
 }
 
+/// Parse number assuming it is base 16, but allow 0x prefix.
+bool parseNumberBase16(StringRef numStr, uint64_t &baseAddress) {
+  if (numStr.startswith_lower("0x"))
+    numStr = numStr.drop_front(2);
+  return numStr.getAsInteger(16, baseAddress);
+}
+
 } // namespace anonymous
 
 namespace lld {
@@ -312,13 +319,10 @@ bool DarwinLdDriver::parse(int argc, con
   else
     ctx.setOutputPath("a.out");
 
+  // Handle -image_base XXX and -seg1addr XXXX
   if (llvm::opt::Arg *imageBase = parsedArgs->getLastArg(OPT_image_base)) {
-    StringRef baseString = imageBase->getValue();
-    if (baseString.startswith("0x"))
-      baseString = baseString.drop_front(2);
-
     uint64_t baseAddress;
-    if (baseString.getAsInteger(16, baseAddress)) {
+    if (parseNumberBase16(imageBase->getValue(), baseAddress)) {
       diagnostics << "error: image_base expects a hex number\n";
       return false;
     } else if (baseAddress < ctx.pageZeroSize()) {





More information about the llvm-commits mailing list