Bug 17843 - GAS 2.24.0 incorrectly rejects a legal asm sequence
Summary: GAS 2.24.0 incorrectly rejects a legal asm sequence
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Richard Sandiford
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-14 20:03 UTC by Geir Johansen
Modified: 2015-03-04 09:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geir Johansen 2015-01-14 20:03:44 UTC
GAS 2.24.0 incorrectly rejects a legal asm sequence:


$ cat test_tls.c
__thread int tls_var;
int get_tls_var() {
    return tls_var;
}

$ clang --target=aarch64 -S test_tls.c

$ cat test_tls.s
	.text
	.file	"test_tls.c"
	.globl	get_tls_var
	.align	2
	.type	get_tls_var,@function
get_tls_var:                            // @get_tls_var
// BB#0:                                // %entry
	movz	x8, #:tprel_g1:tls_var
	movk	x8, #:tprel_g0_nc:tls_var
	mrs	x9, TPIDR_EL0
	ldr	 w10, [x9, x8]
	mov	 w0, w10
	ret
.Ltmp1:
	.size	get_tls_var, .Ltmp1-get_tls_var

	.type	tls_var,@object         // @tls_var
	.section	.tbss,"awT",@nobits
	.globl	tls_var
	.align	2
tls_var:
	.word	0                       // 0x0
	.size	tls_var, 4


	.ident	"clang version 3.5.0 (tags/RELEASE_350/final)"

$ aarch64-linux-gnu-as test_tls.s
test_tls.s: Assembler messages:
test_tls.s:9: Error: the specified relocation type is not allowed for MOVK at operand 2 -- `movk x8,#:tprel_g0_nc:tls_var'
$
Comment 1 Richard Sandiford 2015-02-26 14:32:58 UTC
Testing a fix.
Comment 2 cvs-commit@gcc.gnu.org 2015-03-04 09:10:07 UTC
The master branch has been updated by Richard Sandiford <rsandifo@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e09ab7ac788fd5509adc40b86a3631a3028c1d33

commit e09ab7ac788fd5509adc40b86a3631a3028c1d33
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Mar 4 09:08:49 2015 +0000

    Allow MOVK for R_AARCH64_TLSLE_MOVW_TPREL_G{0,1}NC
    
    bfd/
    	PR gas/17843
    	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Expect
    	R_AARCH64_TLSLE_MOVW_TPREL_G0_NC and R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
    	to be used with MOVK rather than MOVZ.
    
    gas/
    	PR gas/17843
    	* config/tc-aarch64.c (process_movw_reloc_info): Allow
    	R_AARCH64_TLSLE_MOVW_TPREL_G0_NC and R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
    	for MOVK.
    
    gas/testsuite/
    	PR gas/17843
    	* gas/aarch64/tls.s, gas/aarch64/tls.d: Add test for
    	R_AARCH64_TLSLE_MOVW_TPREL_G0/R_AARCH64_TLSLE_MOVW_TPREL_G1_NC
    	sequence.
    
    ld/testsuite/
    	PR gas/17843
    	* ld-aarch64/tlsle.s, ld-aarch64/tlsle.d: New test.
    	* ld-aarch64/aarch64-elf.exp: Run it.
Comment 3 Richard Sandiford 2015-03-04 09:44:09 UTC
Thanks for the report.  Fixed on trunk.