[PATCH] D24128: [ELF] PR30221 - linker script expression parser does not accept '~'

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 13:52:18 PDT 2016

ruiu added inline comments.

Comment at: ELF/LinkerScript.cpp:1236
@@ +1235,3 @@
+static bool readNumber(StringRef Tok, uint64_t &V) {
+  if (Tok.startswith("-"))
+    return Tok.getAsInteger(0, (int64_t &)V);
I think you want to fix the tokenizer (`tokenize` in ScritpParser.cpp) instead of handling `-<number>` in this file. Currently, `-` is allowed to be part of a token, but it is not correct. For example, with that tokenizer, an expression `3-1` is tokenized as `3-1` instead of `3`, `-` and `1`.

I think the only token that can contain `-` as part of it is `-=`. In all other cases, `-` shouldn't stick with adjacent characters.

Because we do not support `-=` yet, we don't care about that. So why don't you remove `-` from tokenize()?

Comment at: ELF/LinkerScript.cpp:1248
@@ +1247,3 @@
+  if (Tok == "~") {
+    Expr E = readParenExpr();
+    return [=](uint64_t Dot) { return ~E(Dot); };
Even if this is what gold does (I didn't test it myself), this looks very weird. If it's true, it seems a gold's bug. I think any primary expression should be allowed after `~`.



More information about the llvm-commits mailing list