[PATCH] D72225: Align branches within 32-Byte boundary(Prefix padding)

Kan Shengchen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 01:53:55 PST 2020


skan added a comment.

In D72225#1818906 <https://reviews.llvm.org/D72225#1818906>, @MaskRay wrote:

> You cannot prepend prefixes to `callq __tls_get_addr` (General-Dynamic/Local-Dynamic TLS models). The code sequence is specially organized to allow linker relaxation. Prepending prefixes may cause the linker to mis-relax the code sequence.
>
>   --x86-align-branch-prefix-size=0
>  
>       4660: 0f 84 df 01 00 00            	je	479 <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0x295>
>       4666: 66 48 8d 3d 00 00 00 00      	leaq	(%rip), %rdi
>   		000000000000466a:  R_X86_64_TLSGD	__rseq_abi-0x4
>       466e: 66 66 48 e8 00 00            	callw	0 <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0xc4>
>   		0000000000004672:  R_X86_64_PLT32	__tls_get_addr-0x4
>       4674: 00 00                        	addb	%al, (%rax)
>       4676: 83 78 04 00                  	cmpl	$0, 4(%rax)
>       467a: 66 0f 1f 44 00 00            	nopw	(%rax,%rax)
>       4680: 0f 88 08 02 00 00            	js	520 <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0x2de>
>  
>   --x86-align-branch-prefix-size=5
>  
>       4660:	0f 84 df 01 00 00    	je     4845 <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0x295>
>       4666:	2e 2e 2e 2e 2e 66 48 	cs cs cs cs data16 lea %cs:0x0(%rip),%rdi        # 4673 <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0xc3>
>       466d:	8d 3d 00 00 00 00 
>   			466f: R_X86_64_TLSGD	__rseq_abi-0x4
>       4673:	2e 66 66 48 e8 00 00 	cs data16 data16 callq 467c <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0xcc>
>       467a:	00 00 
>   			4678: R_X86_64_PLT32	__tls_get_addr-0x4
>       467c:	83 78 04 00          	cmpl   $0x0,0x4(%rax)
>       4680:	0f 88 08 02 00 00    	js     488e <_ZN12_GLOBAL__N_116do_free_no_hooksEPv+0x2de>
>
>
> Note, with -fno-plt, clang will emit `calll *___tls_get_addr at GOT(%ebx)` (32-bit) `callq *__tls_get_addr at GOTPCREL(%rip)` (64-bit). prefix-size= cannot alter such instructions, either.


As far as I know, TLSCALL must have a variant symbol, e.g. `call    ___tls_get_addr at PLT`, `call *___tls_get_addr at GOT(%ecx)`.  The patch did not prepend prefixes to an instruction with variant symbol, which is guranteed by function `X86AsmBackend::shouldAddPrefix()`.  And we can check that with test case

    .text
    .globl  foo
    .p2align  4
  foo:
    .rept 5
    call    ___tls_get_addr at PLT
    .endr
    cmp     %eax, %ebp
    je      foo

Did I miss any TLSCALL?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72225/new/

https://reviews.llvm.org/D72225





More information about the llvm-commits mailing list