[llvm] r305560 - bpf: avoid load from read-only sections

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 12:51:57 PDT 2017


On Fri, Jun 16, 2017 at 8:41 AM, Yonghong Song via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: yhs
> Date: Fri Jun 16 10:41:16 2017
> New Revision: 305560
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305560&view=rev
> Log:
> bpf: avoid load from read-only sections
>
> If users tried to have a structure decl/init code like below
>    struct test_t t = { .memeber1 = 45 };
> It is very likely that compiler will generate a readonly section
> to hold up the init values for variable t. Later load of t members,
> e.g., t.member1 will result in a read from readonly section.
>
> BPF program cannot handle relocation. This will force users to
> write:
>   struct test_t t = {};
>   t.member1 = 45;
> This is just inconvenient and unintuitive.
>
> This patch addresses this issue by implementing BPF PreprocessISelDAG.
> For any load from a global constant structure or an global array of
> constant struct, it attempts to
> translate it into a constant directly. The traversal of the
> constant struct and other constant data structures are similar
> to where the assembler emits read-only sections.
>
> Four different unit test cases are also added to cover
> different scenarios.
>
> Signed-off-by: Yonghong Song <yhs at fb.com>

I'm afraid this (or another one of your recent commits) broke the GCC
7 build with -Werror.
Can you please take a look?

[1047/1897] Building CXX object
lib/Target/BPF/CMakeFiles/LLVMBPFCodeGen.dir/BPFISelDAGToDAG.cpp.o
../lib/Target/BPF/BPFISelDAGToDAG.cpp: In member function ‘virtual
void {anonymous}::BPFDAGToDAGISel::PreprocessISelDAG()’:
../lib/Target/BPF/BPFISelDAGToDAG.cpp:264:26: warning: dereferencing
type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
       val = *(uint16_t *)new_val;
                          ^~~~~~~
../lib/Target/BPF/BPFISelDAGToDAG.cpp:266:26: warning: dereferencing
type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
       val = *(uint32_t *)new_val;
                          ^~~~~~~
../lib/Target/BPF/BPFISelDAGToDAG.cpp:268:26: warning: dereferencing
type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
       val = *(uint64_t *)new_val;
                          ^~~~~~~
../lib/Target/BPF/BPFISelDAGToDAG.cpp: In member function ‘bool
{anonymous}::BPFDAGToDAGISel::getConstantFieldValue(const
llvm::GlobalAddressSDNode*, uint64_t, uint64_t, unsigned char*)’:
../lib/Target/BPF/BPFISelDAGToDAG.cpp:328:36: warning: dereferencing
type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
   bool endian_match = *(uint16_t *)test_buf == test_val;
                                    ^~~~~~~~


--
Davide


More information about the llvm-commits mailing list