[PATCH] D49673: [AArch64] Add Tiny Code Model for AArch64

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 31 05:45:45 PDT 2018


peter.smith added a comment.

One example where gcc (7.1 in my case) will generate different code for tls is:

  __thread int foo __attribute__((tls_model("initial-exec")));
  
  int func(void) {
      return foo;
  }

aarch64-linux-gnu-gcc -S tls.c -O1 -mcmodel=small -o -

  func:
  	adrp	x0, :gottprel:.LANCHOR0
  	ldr	x0, [x0, #:gottprel_lo12:.LANCHOR0]
  	mrs	x1, tpidr_el0
  	ldr	w0, [x1, x0]
  	ret
  ...
  	.section	.tbss,"awT", at nobits
  	.align	2
  	.set	.LANCHOR0,. + 0
  	.type	foo, %object
  	.size	foo, 4
  foo:
  	.zero	4

whereas with -mcmodel=tiny

  func:
  	mrs	x1, tpidr_el0
  	ldr	x0, :gottprel:.LANCHOR0
  	add	x0, x0, x1
  	ldr	w0, [x0]
  	ret

I've not seen any differences in the other TLS models.

I think it is probably fine to keep TLS access using the small code model, at least initially. I wouldn't expect too many embedded systems to implement TLS and if they did they could probably use the local-exec model at compile time or have the linker relax to local-exec. Haven't had a chance to look at the rest of the patch yet, will hope to do so shortly.


https://reviews.llvm.org/D49673





More information about the llvm-commits mailing list