[Bug target/82303] Better PIE/PIC code generation for kernel code (x86_64 & arm64)

hjl.tools at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 23 21:18:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82303

--- Comment #15 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Thomas Garnier from comment #14)
> Correcting what I said before, it is about re-enabling switch folding (or
> switch optimization).
> 
> Basically without PIE (-fno-PIE) with -O2, a switch can be optimized to be:
> 
> 0000000000000000 <phy_modes>:
>    0:	b8 00 00 00 00       	mov    $0x0,%eax
> 			1: R_X86_64_32	.rodata.str1.1
>    5:	83 ff 16             	cmp    $0x16,%edi
>    8:	77 0a                	ja     14 <phy_modes+0x14>
>    a:	89 ff                	mov    %edi,%edi
>    c:	48 8b 04 fd 00 00 00 	mov    0x0(,%rdi,8),%rax
>   13:	00 
> 			10: R_X86_64_32S	.rodata
>   14:	c3                   	retq   
> 

The problem is that R_X86_64_32 isn't PIC:

/usr/local/bin/ld: x.o: relocation R_X86_64_32 against `.rodata.str1.1' can not
be used when making a PIE object; recompile with -fPIC


More information about the Gcc-bugs mailing list