[Git][ghc/ghc][master] [PEi386] Mask SYM_TYPE_DUP_DISCARD in makeSymbolExtra

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Oct 28 11:07:25 UTC 2023



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


Commits:
34f06334 by Moritz Angermann at 2023-10-28T07:06:53-04:00
[PEi386] Mask SYM_TYPE_DUP_DISCARD in makeSymbolExtra

48e391952c17ff7eab10b0b1456e3f2a2af28a9b
introduced `SYM_TYPE_DUP_DISCARD` to the bitfield.

The linker however, failed to mask the `SYM_TYPE_DUP_DISCARD` value.
Thus `== SYM_TYPE_CODE` comparisons easily failed. This lead to us
relocating DATA lookups (GOT) into E8 (call) and E9 (jump) instructions.

- - - - -


1 changed file:

- rts/linker/PEi386.c


Changes:

=====================================
rts/linker/PEi386.c
=====================================
@@ -1939,29 +1939,32 @@ static size_t
 makeSymbolExtra_PEi386( ObjectCode* oc, uint64_t index STG_UNUSED, size_t s, char* symbol STG_UNUSED, SymType type )
 {
     SymbolExtra *extra;
-
-    if (type == SYM_TYPE_CODE) {
-        // jmp *-14(%rip)
-        extra = m32_alloc(oc->rx_m32, sizeof(SymbolExtra), 8);
-        CHECK(extra);
-        extra->addr = (uint64_t)s;
-        static uint8_t jmp[] = { 0xFF, 0x25, 0xF2, 0xFF, 0xFF, 0xFF };
-        memcpy(extra->jumpIsland, jmp, 6);
-        IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(code): %s -> %p\n", symbol, &extra->jumpIsland));
-        return (size_t)&extra->jumpIsland;
-    } else if (type == SYM_TYPE_INDIRECT_DATA) {
-        extra = m32_alloc(oc->rw_m32, sizeof(SymbolExtra), 8);
-        CHECK(extra);
-        void *v = *(void**) s;
-        extra->addr = (uint64_t)v;
-        IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(data): %s -> %p\n", symbol, &extra->addr));
-        return (size_t)&extra->addr;
-    } else {
-        extra = m32_alloc(oc->rw_m32, sizeof(SymbolExtra), 8);
-        CHECK(extra);
-        extra->addr = (uint64_t)s;
-        IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(indirect-data): %s -> %p\n", symbol, &extra->addr));
-        return (size_t)&extra->addr;
+    switch(type & ~SYM_TYPE_DUP_DISCARD) {
+        case SYM_TYPE_CODE: {
+            // jmp *-14(%rip)
+            extra = m32_alloc(oc->rx_m32, sizeof(SymbolExtra), 8);
+            CHECK(extra);
+            extra->addr = (uint64_t)s;
+            static uint8_t jmp[] = { 0xFF, 0x25, 0xF2, 0xFF, 0xFF, 0xFF };
+            memcpy(extra->jumpIsland, jmp, 6);
+            IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(code): %s -> %p\n", symbol, &extra->jumpIsland));
+            return (size_t)&extra->jumpIsland;
+        }
+        case SYM_TYPE_INDIRECT_DATA: {
+            extra = m32_alloc(oc->rw_m32, sizeof(SymbolExtra), 8);
+            CHECK(extra);
+            void *v = *(void**) s;
+            extra->addr = (uint64_t)v;
+            IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(data): %s -> %p\n", symbol, &extra->addr));
+            return (size_t)&extra->addr;
+        }
+        default: {
+            extra = m32_alloc(oc->rw_m32, sizeof(SymbolExtra), 8);
+            CHECK(extra);
+            extra->addr = (uint64_t)s;
+            IF_DEBUG(linker_verbose, debugBelch("makeSymbolExtra(indirect-data): %s -> %p\n", symbol, &extra->addr));
+            return (size_t)&extra->addr;
+        }
     }
 }
 



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/34f06334025521c2440ebedb0237697fbcc3c6de
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/20231028/76103b9f/attachment-0001.html>


More information about the ghc-commits mailing list