aboutsummaryrefslogtreecommitdiff
path: root/gdb/infcmd.c
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2023-11-16 09:35:03 -0800
committerDavid Faust <david.faust@oracle.com>2023-11-17 13:22:27 -0800
commite5d6f72eb3db66939f0d14e78056e118e83aca37 (patch)
tree7c573f152f6cc08a17865deb7b305250a0424042 /gdb/infcmd.c
parent413366203156a0483d06a97b3f02b64ba6a215cc (diff)
downloadgdb-e5d6f72eb3db66939f0d14e78056e118e83aca37.zip
gdb-e5d6f72eb3db66939f0d14e78056e118e83aca37.tar.gz
gdb-e5d6f72eb3db66939f0d14e78056e118e83aca37.tar.bz2
bpf: avoid creating wrong symbols while parsing
To support the "pseudo-C" asm dialect in BPF, the BPF parser must often attempt multiple different templates for a single instruction. In some cases this can cause the parser to incorrectly parse part of the instruction opcode as an expression, which leads to the creation of a new undefined symbol. Once the parser recognizes the error, the expression is discarded and it tries again with a new instruction template. However, symbols created during the process are added to the symbol table and are not removed even if the expression is discarded. This is a problem for BPF: generally the assembled object will be loaded directly to the Linux kernel, without being linked. These erroneous parser-created symbols are rejected by the kernel BPF loader, and the entire object is refused. This patch remedies the issue by tentatively creating symbols while parsing instruction operands, and storing them in a temporary list rather than immediately inserting them into the symbol table. Later, after the parser is sure that it has correctly parsed the instruction, those symbols are committed to the real symbol table. This approach is modeled directly after Jan Beulich's patch for RISC-V: commit 7a29ee290307087e1749ce610207e93a15d0b78d RISC-V: adjust logic to avoid register name symbols Many thanks to Jan for recognizing the problem as similar, and pointing me to that patch. gas/ * config/tc-bpf.c (parsing_insn_operands): New. (parse_expression): Set it here. (deferred_sym_rootP, deferred_sym_lastP): New. (orphan_sym_rootP, orphan_sym_lastP): New. (bpf_parse_name): New. (parse_error): Clear deferred symbol list on error. (md_assemble): Clear parsing_insn_operands. Commit deferred symbols to symbol table on successful parse. * config/tc-bpf.h (md_parse_name): Define to... (bpf_parse_name): ...this. New prototype. * testsuite/gas/bpf/asm-extra-sym-1.s: New test source. * testsuite/gas/bpf/asm-extra-sym-1.d: New test. * testsuite/gas/bpf/bpf.exp: Run new test.
Diffstat (limited to 'gdb/infcmd.c')
0 files changed, 0 insertions, 0 deletions