util: Implement PIC assembly for the aarch64.
authorGabe Black <gabeblack@google.com>
Fri, 27 Mar 2020 08:05:35 +0000 (01:05 -0700)
committerGabe Black <gabeblack@google.com>
Thu, 9 Apr 2020 05:31:09 +0000 (05:31 +0000)
When accessing m5_mem and building PIC code, we need to get the address
of m5_mem out of the global offset table, and then load the value from
there. If we try to load from m5_mem directly, the assembled code has a
relocation type the linker can't handle when building a shared object.

Change-Id: Ieb19c3d17c37ef810559ee24b68886b18ddcc869
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27212
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
util/m5/src/m5op_arm_A64.S

index c0224e21b0d839baf1dc13b1b5aa3732208e8bcd..6f9f0380835a049461869151a7d18ab67f1cff70 100644 (file)
 .macro m5op_func, name, func
         .globl \name
         \name:
-        ldr x9, m5_mem
+        // Load the value of m5_mem into x9...
+#if defined(M5OP_PIC)
+        // using the global offset table.
+        adrp x9, :got:m5_mem
+        ldr x9, [ x9, #:got_lo12:m5_mem ]
+        ldr x9, [ x9 ]
+#else
+        // normally.
+        adrp x9, m5_mem
+        ldr x9, [ x9, #:lo12:m5_mem ]
+#endif
         movz x10, #(\func << 8)
         ldr x0, [ x9, x10 ]
         ret