From 703d3f25976c98bcf0e4717087c5a51b92c5f51a Mon Sep 17 00:00:00 2001 From: Greg McGary Date: Mon, 21 Sep 2020 19:02:12 -0700 Subject: [lld-macho] Make lld::getInteger() tolerate leading "0x"/"0X" when base is 16 ld64 is cool with leading `0x` for hex command-line args, and we should be also. Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D88065 --- lld/Common/Args.cpp | 5 ++++- lld/test/MachO/headerpad.s | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lld') diff --git a/lld/Common/Args.cpp b/lld/Common/Args.cpp index 507830f..afc5782 100644 --- a/lld/Common/Args.cpp +++ b/lld/Common/Args.cpp @@ -33,7 +33,10 @@ static int64_t getInteger(opt::InputArgList &args, unsigned key, return Default; int64_t v; - if (to_integer(a->getValue(), v, base)) + StringRef s = a->getValue(); + if (base == 16 && (s.startswith("0x") || s.startswith("0X"))) + s = s.drop_front(2); + if (to_integer(s, v, base)) return v; StringRef spelling = args.getArgString(a->getIndex()); diff --git a/lld/test/MachO/headerpad.s b/lld/test/MachO/headerpad.s index a5e6ced..a8e1dba 100644 --- a/lld/test/MachO/headerpad.s +++ b/lld/test/MachO/headerpad.s @@ -21,8 +21,13 @@ # RUN: lld -flavor darwinnew -o %t %t.o -headerpad 11 # RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11 -# PAD11: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags -# PAD11-NEXT: MH_MAGIC_64 X86_64 ALL LIB64 EXECUTE 9 [[#%u, CMDSIZE:]] {{.*}} +# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0x11 +# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11 +# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0X11 +# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11 + +# PAD11: magic {{.+}} ncmds sizeofcmds flags +# PAD11-NEXT: MH_MAGIC_64 {{.+}} 9 [[#%u, CMDSIZE:]] {{.*}} # PAD11: sectname __text # PAD11-NEXT: segname __TEXT # PAD11-NEXT: addr -- cgit v1.1