Re: [PATCH 2/2] bpf: allow BSS symbols to be global symbols

2021-04-23 Thread YiFei Zhu via Gcc-patches
On Fri, Apr 23, 2021 at 12:25 PM David Faust  wrote:
> I've just checked in both patches to master and GCC 10 on your behalf.

On 4/22/21 11:54 PM, Jose E. Marchesi via Gcc-patches wrote:
> Thanks for the patch.
> This is OK for both master and GCC 10.

Thanks to both of you :)

YiFei Zhu


[PATCH 2/2] bpf: allow BSS symbols to be global symbols

2021-04-22 Thread YiFei Zhu via Gcc-patches
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:

   b foo
  0004 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:

   B foo
  0004 b bar

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

2021-04-22  YiFei Zhu  

gcc/

* config/bpf/bpf.h (ASM_OUTPUT_ALIGNED_BSS): Use .type and .lcomm.
---
 gcc/config/bpf/bpf.h | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h
index 7ff2f310d583..55beecbcb364 100644
--- a/gcc/config/bpf/bpf.h
+++ b/gcc/config/bpf/bpf.h
@@ -414,9 +414,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.  */
 
-- 
2.31.1



[PATCH 1/2] bpf: align function entry point to 64 bits

2021-04-22 Thread YiFei Zhu via Gcc-patches
Libbpf does not treat paddings after functions well. If function
symbols does not cover a whole text section, it will emit error
similar to:

  libbpf: sec '.text': failed to find program symbol at offset 56

Each instruction in BPF is a multiple of 8 bytes, so align the
functions to 8 bytes, similar to how clang does it.

2021-04-22  YiFei Zhu  

gcc/

* config/bpf/bpf.h (FUNCTION_BOUNDARY): Set to 64.
---
 gcc/config/bpf/bpf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h
index ef0123b56a63..7ff2f310d583 100644
--- a/gcc/config/bpf/bpf.h
+++ b/gcc/config/bpf/bpf.h
@@ -57,8 +57,8 @@
64-bit at any time.  */
 #define STACK_BOUNDARY 64
 
-/* Function entry points are aligned to 128 bits.  */
-#define FUNCTION_BOUNDARY 128
+/* Function entry points are aligned to 64 bits.  */
+#define FUNCTION_BOUNDARY 64
 
 /* Maximum alignment required by data of any type.  */
 #define BIGGEST_ALIGNMENT 64
-- 
2.31.1