[ELF] Fix assertion failure when PROVIDE/HIDDEN/PROVIDE_HIDDEN does not have =

This commit is contained in:
Fangrui Song 2022-06-25 20:26:47 -07:00
parent fe0de25b21
commit 21bf6bb3d3
2 changed files with 13 additions and 1 deletions

View File

@ -1017,7 +1017,14 @@ std::array<uint8_t, 4> ScriptParser::readFill() {
SymbolAssignment *ScriptParser::readProvideHidden(bool provide, bool hidden) {
expect("(");
SymbolAssignment *cmd = readSymbolAssignment(next());
StringRef name = next(), eq = peek();
if (eq != "=") {
setError("= expected, but got " + next());
while (!atEOF() && next() != ")")
;
return nullptr;
}
SymbolAssignment *cmd = readSymbolAssignment(name);
cmd->provide = provide;
cmd->hidden = hidden;
expect(")");

View File

@ -73,6 +73,11 @@
# SIMPLE2: 0000000000000100 g *ABS* 0000000000000000 bar
# SIMPLE2: 0000000000000100 g *ABS* 0000000000000000 baz
# RUN: echo 'PROVIDE(somesym + 1);' > %t.script
# RUN: not ld.lld -T %t.script %t -o /dev/null 2>&1 | FileCheck %s --check-prefix=PROVIDE-ERR
# PROVIDE-ERR: {{.*}}:1: = expected, but got +
.global _start
_start:
nop