]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bpf: allow BSS symbols to be global symbols
authorYiFei Zhu <zhuyifei1999@gmail.com>
Thu, 22 Apr 2021 10:05:57 +0000 (05:05 -0500)
committerDavid Faust <david.faust@oracle.com>
Wed, 28 Apr 2021 16:04:40 +0000 (09:04 -0700)
Prior to this, a BSS declaration such as:

  int foo;
  static int bar;

Generates:

  .global foo
  .local  foo
  .comm   foo,4,4
  .local  bar
  .comm   bar,4,4

Creating symbols:

  0000000000000000 b foo
  0000000000000004 b bar

Both symbols are local. However, libbpf bpf_object__variable_offset
rquires symbols to be STB_GLOBAL & STT_OBJECT for data section lookup.
This patch makes the same declaration generate:

  .global foo
  .type   foo, @object
  .lcomm  foo,4,4
  .local  bar
  .comm   bar,4,4

Creating symbols:

  0000000000000000 B foo
  0000000000000004 b bar

And libbpf will be okay with looking up the global symbol "foo".

2021-04-22  YiFei Zhu  <zhuyifei1999@gmail.com>

gcc/

* config/bpf/bpf.h (ASM_OUTPUT_ALIGNED_BSS): Use .type and .lcomm.

(cherry picked from commit 886b6c1e8af502b69e3f318b9830b73b88215878)

gcc/config/bpf/bpf.h

index 6a3907fb61816f80d6105f9520980a841a71a93c..4c5b19e262b98bce4df359a213db700f9b1e130c 100644 (file)
@@ -422,9 +422,15 @@ enum reg_class
    Try to use asm_output_aligned_bss to implement this macro.  */
 
 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN)  \
-  do {                                                         \
-    ASM_OUTPUT_ALIGNED_LOCAL (FILE, NAME, SIZE, ALIGN);                \
-  } while (0)
+  do                                                                   \
+    {                                                                  \
+      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");                        \
+      fprintf ((FILE), "%s", "\t.lcomm\t");                            \
+      assemble_name ((FILE), (NAME));                                  \
+      fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",       \
+              (SIZE), (ALIGN) / BITS_PER_UNIT);                        \
+    }                                                                  \
+  while (0)
 
 /*** Output and Generation of Labels.  */