[PATCH] D24128: [ELF] PR30221 - linker script expression parser does not accept '~'
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 2 07:18:24 PDT 2016
ruiu added inline comments.
================
Comment at: ELF/LinkerScript.cpp:1248
@@ +1247,3 @@
+ if (Tok == "~") {
+ Expr E = readParenExpr();
+ return [=](uint64_t Dot) { return ~E(Dot); };
----------------
grimar wrote:
> ruiu wrote:
> > grimar wrote:
> > > ruiu wrote:
> > > > 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 `~`.
> > > My consern about gold/ld is that users of lld can write some script using our syntax and have a problems if they decide to switch to gold/ld for some reason. I think it is always better to have script files fully compatible if it is possible.
> > > Though it is always more convinent to write ~XXX then ~(XXX), therefore my position here is wonky.
> > I tried
> >
> > echo 'SECTIONS { foo = ~0; }' > x
> > echo 'int main() {}' | /ssd/clang/bin/clang -xc - -o /dev/null -fuse-ld=gold -Wl,--script=./x
> >
> > and gold didn't complain the absence of () after ~. I believe you made a mistake.
> >
> > ~ operator is defined in gold's yyscript.y as follows.
> >
> > exp:
> > '(' exp ')'
> > { $$ = $2; }
> > | '-' exp %prec UNARY
> > { $$ = script_exp_unary_minus($2); }
> > | '!' exp %prec UNARY
> > { $$ = script_exp_unary_logical_not($2); }
> > | '~' exp %prec UNARY
> > { $$ = script_exp_unary_bitwise_not($2); }
> > | '+' exp %prec UNARY
> > { $$ = $2; }
> > | exp '*' exp
> > { $$ = script_exp_binary_mult($1, $3); }
> > | ...
> >
> > As you can see, `exp` is expected after ~.
> >
> > Finally, it just doesn't make sense to require `(` only after `~` unary operator while any expression is allowed for other unary operators. If you design a language, you'd never do that.
> Probably I made mistake that it was gold. But ld definetely does not like it:
>
> . = 0x10000 + ~4;
>
> test.script:3: undefined symbol `~4' referenced in expression
>
>
>
>
That's a problem of the ld's tokenizer. The grammar still allows any expression after `~`. Insert a space after `~`, then you'll find that () is not actually required after `~`.
Repository:
rL LLVM
https://reviews.llvm.org/D24128
More information about the llvm-commits
mailing list