public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] gas,bpf: cleanup bad symbols created while parsing
@ 2023-11-14 17:58 David Faust
  2023-11-14 17:58 ` [PATCH 1/2] gas: add symbol_table_remove David Faust
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: David Faust @ 2023-11-14 17:58 UTC (permalink / raw)
  To: binutils; +Cc: jose.marchesi

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 lead to a call to expression () which creates a
symbol, and only later the template is determined not to match and the
expression is discarded.

However, symbols created during this process are added to the symbol
table and are not removed if the expression is discarded.

This is a problem for BPF: generally the assembled object will be
loaded directly by the Linux kernel, without being linked.  The kernel
BPF loader requires that BTF information is available for every symbol
in a loaded BPF program, which will not be available for these symbols
erroneously created by the parser.

Patch 1 adds a symbol_table_remove () function to symbols.c and
exposes it in the header, since symbol_remove () is not sufficient to
prevent such symbols being written in the symbol table of the resulting
ELF object.

Patch 2 detects cases in the BPF parser where a call to expression ()
created any new symbol(s), but the parsing of the instruction as a
whole against the current template failed.  In that case the created
symbols are deleted.

David Faust (2):
  gas: add symbol_table_remove
  bpf: remove symbols created during failed parse

 gas/config/tc-bpf.c                     | 30 +++++++++++++++++++++++++
 gas/symbols.c                           | 10 +++++++++
 gas/symbols.h                           |  1 +
 gas/testsuite/gas/bpf/asm-extra-sym-1.d |  7 ++++++
 gas/testsuite/gas/bpf/asm-extra-sym-1.s |  1 +
 gas/testsuite/gas/bpf/asm-extra-sym-2.d |  7 ++++++
 gas/testsuite/gas/bpf/asm-extra-sym-2.s |  8 +++++++
 gas/testsuite/gas/bpf/bpf.exp           |  4 ++++
 8 files changed, 68 insertions(+)
 create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-1.d
 create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-1.s
 create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-2.d
 create mode 100644 gas/testsuite/gas/bpf/asm-extra-sym-2.s

-- 
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-15 21:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 17:58 [PATCH 0/2] gas,bpf: cleanup bad symbols created while parsing David Faust
2023-11-14 17:58 ` [PATCH 1/2] gas: add symbol_table_remove David Faust
2023-11-14 17:58 ` [PATCH 2/2] bpf: remove symbols created during failed parse David Faust
2023-11-14 22:13 ` [PATCH 0/2] gas,bpf: cleanup bad symbols created while parsing David Faust
2023-11-15  9:49 ` Jan Beulich
2023-11-15 21:57   ` David Faust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).