Skip to content

Commit

Permalink
[ELF] Emit only one error if -z max-page-size without value
Browse files Browse the repository at this point in the history
In r305364, Rui changed the mechanism that parses -z option values slightly.
This caused a bug, as demonstrated by this test, which now fails:

---
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t -z max-page-size

.global _start
_start:
  nop
---

Before, the link succeeded and set the max-page-size to the target default.

After we get the following two error messages:
"invalid max-page-size: "
"max-page-size: value isn't a power of 2"

The latter error is because an uninitialised variable ends up being passed back
to getMaxPageSize).

This change ensures we only get the first error.

Reviewers: ruiu

Differential Revision: https://reviews.llvm.org/D34234

llvm-svn: 305679
  • Loading branch information
jh7370 committed Jun 19, 2017
1 parent dad1e1a commit 38e67e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lld/ELF/Driver.cpp
Expand Up @@ -301,7 +301,7 @@ static uint64_t getZOptionValue(opt::InputArgList &Args, StringRef Key,
for (auto *Arg : Args.filtered(OPT_z)) {
std::pair<StringRef, StringRef> KV = StringRef(Arg->getValue()).split('=');
if (KV.first == Key) {
uint64_t Result;
uint64_t Result = Default;
if (!to_integer(KV.second, Result))
error("invalid " + Key + ": " + KV.second);
return Result;
Expand Down
9 changes: 9 additions & 0 deletions lld/test/ELF/invalid-z.s
@@ -0,0 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: not ld.lld %t.o -o %t -z max-page-size 2>&1 | FileCheck %s
# CHECK: invalid max-page-size
# CHECK-NOT: error

.global _start
_start:
nop

0 comments on commit 38e67e8

Please sign in to comment.