]> git.ipfire.org Git - thirdparty/gcc.git/commit
bpf: quote section names whenever necessary in assembly output
authorJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 1 Dec 2023 09:38:00 +0000 (10:38 +0100)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 1 Dec 2023 09:42:40 +0000 (10:42 +0100)
commitb506834e7fa939e43f784d417f0e9b4ded91ebd2
tree03678147503f1c013f751efa357894509109ca52
parent6563d6767ed0f702458f8975cd5d73676c4604cc
bpf: quote section names whenever necessary in assembly output

In BPF section names are used to encode the kind of BPF program and
other metadata, involving all sort of non alphanumeric characters.

For example:

  /* use auto-attach format for section definition. */
  SEC("uretprobe//proc/self/exe:trigger_func2")
  int handle_uretprobe_byname(struct pt_regs *ctx)
  {
   uretprobe_byname_res = 6;
   return 0;
  }

The above requires to quote the section name in the output assembly
file, since otherwise the // in the name would be interpreted by the
assembler lexer as the beginning of a line comment.

This patch makes the BPF backend to emit quoted section names in
.section directives if the name requires to be quoted.  Simple section
names whose constituent characters are in the set [0-9a-zA-Z_] are
still emitted unquoted.

Tested in target bpf-unknown-none-gcc and host x86_64-linux-gnu.

gcc/ChangeLog

* config/bpf/bpf.cc (bpf_asm_named_section): New function.
(TARGET_ASM_NAMED_SECTION): Set to bpf_asm_named_section.

gcc/testsuite/ChangeLog

* gcc.target/bpf/section-name-quoting-1.c: New test.
gcc/config/bpf/bpf.cc
gcc/testsuite/gcc.target/bpf/section-name-quoting-1.c [new file with mode: 0644]