[Git][ghc/ghc][master] AARCH64 linker: skip NONE relocations

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Aug 13 17:39:00 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
c749bdfd by Sylvain Henry at 2024-08-13T13:38:41-04:00
AARCH64 linker: skip NONE relocations

This patch is part of the patches upstreamed from haskell.nix.
See https://github.com/input-output-hk/haskell.nix/pull/1960 for the
original report/patch.

- - - - -


7 changed files:

- rts/linker/elf_reloc_aarch64.c
- testsuite/tests/rts/linker/Makefile
- testsuite/tests/rts/linker/T7072-obj.c → testsuite/tests/rts/linker/T7072.c
- testsuite/tests/rts/linker/all.T
- testsuite/tests/rts/linker/T7072-main.c → testsuite/tests/rts/linker/load-object.c
- + testsuite/tests/rts/linker/reloc-none.c
- + testsuite/tests/rts/linker/reloc-none.stderr


Changes:

=====================================
rts/linker/elf_reloc_aarch64.c
=====================================
@@ -294,10 +294,13 @@ relocateObjectCodeAarch64(ObjectCode * oc) {
         for (unsigned i = 0; i < relTab->n_relocations; i++) {
             Elf_Rel *rel = &relTab->relocations[i];
 
+            if(ELF64_R_TYPE(rel->r_info) == COMPAT_R_AARCH64_NONE)
+              continue;
+
             ElfSymbol *symbol =
                     findSymbol(oc,
                                relTab->sectionHeader->sh_link,
-                               ELF64_R_SYM((Elf64_Xword)rel->r_info));
+                               ELF64_R_SYM(rel->r_info));
 
             CHECK(0x0 != symbol);
 
@@ -320,10 +323,13 @@ relocateObjectCodeAarch64(ObjectCode * oc) {
 
             Elf_Rela *rel = &relaTab->relocations[i];
 
+            if(ELF64_R_TYPE(rel->r_info) == COMPAT_R_AARCH64_NONE)
+              continue;
+
             ElfSymbol *symbol =
                     findSymbol(oc,
                                relaTab->sectionHeader->sh_link,
-                               ELF64_R_SYM((Elf64_Xword)rel->r_info));
+                               ELF64_R_SYM(rel->r_info));
 
             CHECK(0x0 != symbol);
             if(0x0 == symbol->addr)


=====================================
testsuite/tests/rts/linker/Makefile
=====================================
@@ -120,10 +120,9 @@ linker_error3:
 
 .PHONY: T7072
 T7072:
-	"$(TEST_HC)" -c T7072-obj.c -o T7072-obj.o
-	"$(TEST_HC)" -c T7072-main.c -o T7072-main.o
-	"$(TEST_HC)" T7072-main.c -o T7072-main -no-hs-main -debug
-	./T7072-main T7072-obj.o
+	"$(TEST_HC)" load-object.c -o load-object -no-hs-main -debug
+	"$(TEST_HC)" -c T7072.c -o T7072.o
+	./load-object T7072.o
 
 .PHONY: T20494
 T20494:
@@ -140,3 +139,9 @@ T20918:
 T21618:
 	"$(TEST_HC)" -c T21618_c.c -o T21618_c.o
 	echo main | '$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) T21618_c.o T21618.hs
+
+.PHONY: reloc-none
+reloc-none:
+	"$(TEST_HC)" load-object.c -o load-object -no-hs-main -debug
+	"$(TEST_HC)" -c reloc-none.c -o reloc-none.o
+	./load-object reloc-none.o


=====================================
testsuite/tests/rts/linker/T7072-obj.c → testsuite/tests/rts/linker/T7072.c
=====================================


=====================================
testsuite/tests/rts/linker/all.T
=====================================
@@ -142,7 +142,7 @@ test('rdynamic', [ unless(opsys('linux') or opsys('mingw32'), skip)
 
 
 test('T7072',
-	[extra_files(['T7072-main.c', 'T7072-obj.c']),
+	[extra_files(['load-object.c', 'T7072.c']),
 		unless(opsys('linux'), skip),
 		req_rts_linker],
 	makefile_test, ['T7072'])
@@ -160,3 +160,11 @@ test('T20918',
 test('T21618',
      [unless(opsys('mingw32'), skip), req_rts_linker],
      makefile_test, ['T21618'])
+
+# test R_AARCH64_NONE relocation support
+test('reloc-none',
+	[extra_files(['load-object.c', 'reloc-none.c']),
+		unless(arch('aarch64'), skip),
+                unless(opsys('linux'), skip),
+		req_rts_linker],
+	makefile_test, ['reloc-none'])


=====================================
testsuite/tests/rts/linker/T7072-main.c → testsuite/tests/rts/linker/load-object.c
=====================================
@@ -12,10 +12,10 @@ int main (int argc, char *argv[])
 
     initLinker_(0);
 
-    // Load object file argv[1] repeatedly
+    // Load object file argv[1] once
 
     if (argc != 2) {
-        errorBelch("usage: T7072-main <object-file>");
+        errorBelch("usage: load-object <object-file>");
         exit(1);
     }
 


=====================================
testsuite/tests/rts/linker/reloc-none.c
=====================================
@@ -0,0 +1,8 @@
+static int a[0];
+
+int foo(){
+    asm(".reloc ., R_AARCH64_NONE, 10");
+    asm(".reloc ., R_AARCH64_NONE, a");
+    asm(".reloc ., R_AARCH64_NONE, a+10");
+    return a[0];
+}


=====================================
testsuite/tests/rts/linker/reloc-none.stderr
=====================================
@@ -0,0 +1 @@
+loading succeeded
\ No newline at end of file



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c749bdfd3e21d712dc2b966482eb010165bdeebe

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c749bdfd3e21d712dc2b966482eb010165bdeebe
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240813/1c2dd05c/attachment-0001.html>


More information about the ghc-commits mailing list