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

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 13:03:35 PDT 2017


Davide,

I will look into this.

Thanks,

Yonghong

On 6/16/17 12:51 PM, Davide Italiano wrote:
> 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: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D305560-26view-3Drev&d=DwIFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=HpkKzi7dIIkbwEzbiMSqfe1uTGLVNFO7U5hB9wDZOM0&s=8o7C88-Ngxgx6tn7uHHzEmFlvU_o9ypQoq-dWojzOAs&e=
>> 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