[Git][ghc/ghc][wip/ghc-9.8] 3 commits: gitlab-ci: Mark linker_unload_native as broken on Alpine

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Thu Jul 27 15:19:28 UTC 2023



Ben Gamari pushed to branch wip/ghc-9.8 at Glasgow Haskell Compiler / GHC


Commits:
a3756043 by Ben Gamari at 2023-07-24T11:37:25-04:00
gitlab-ci: Mark linker_unload_native as broken on Alpine

Due to lack of dlinfo() support, which is necessary for sound unloading
support.

- - - - -
877ec97b by Ben Gamari at 2023-07-25T12:57:55-04:00
linker/PEi386: Don't sign-extend symbol section number

Previously we incorrectly interpreted PE section numbers as signed
values. However, this isn't the case; rather, it's an unsigned 16-bit number
with a few special bit-patterns (0xffff and 0xfffe). This resulted in #22941
as the linker would conclude that the sections were invalid.

Fixing this required quite a bit of refactoring.

Closes #22941.

- - - - -
f2f16867 by Ben Gamari at 2023-07-27T10:20:03-04:00
ghc-prim: Bump version to 0.11

- - - - -


11 changed files:

- .gitlab/gen_ci.hs
- .gitlab/jobs.yaml
- libraries/base/base.cabal
- libraries/ghc-bignum/ghc-bignum.cabal
- libraries/ghc-compact/ghc-compact.cabal
- libraries/ghc-heap/ghc-heap.cabal.in
- libraries/ghc-prim/ghc-prim.cabal
- libraries/ghci/ghci.cabal.in
- libraries/text
- rts/linker/PEi386.c
- rts/linker/PEi386.h


Changes:

=====================================
.gitlab/gen_ci.hs
=====================================
@@ -434,7 +434,8 @@ distroVariables Alpine = mconcat
   , "HADRIAN_ARGS" =: "--docs=no-sphinx"
     -- encoding004: due to lack of locale support
     -- T10458, ghcilink002: due to #17869
-  , "BROKEN_TESTS" =: "encoding004 T10458"
+    -- linker_unload_native: due to lack of dlinfo() support
+  , "BROKEN_TESTS" =: "encoding004 T10458 linker_unload_native"
   ]
 distroVariables Centos7 = mconcat [
   "HADRIAN_ARGS" =: "--docs=no-sphinx"


=====================================
.gitlab/jobs.yaml
=====================================
@@ -598,7 +598,7 @@
     "variables": {
       "BIGNUM_BACKEND": "native",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-int_native-validate+fully_static",
-      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458",
+      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "validate+fully_static",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--docs=no-sphinx",
@@ -660,7 +660,7 @@
     "variables": {
       "BIGNUM_BACKEND": "gmp",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-validate",
-      "BROKEN_TESTS": "encoding004 T10458",
+      "BROKEN_TESTS": "encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "validate",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--docs=no-sphinx",
@@ -722,7 +722,7 @@
     "variables": {
       "BIGNUM_BACKEND": "gmp",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-validate+fully_static",
-      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458",
+      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "validate+fully_static",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--docs=no-sphinx",
@@ -2536,7 +2536,7 @@
     "variables": {
       "BIGNUM_BACKEND": "native",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-int_native-release+fully_static",
-      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458",
+      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "release+fully_static",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--hash-unit-ids --docs=no-sphinx",
@@ -2599,7 +2599,7 @@
     "variables": {
       "BIGNUM_BACKEND": "gmp",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-release+fully_static+no_split_sections",
-      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458",
+      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "release+fully_static+no_split_sections",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--hash-unit-ids --docs=no-sphinx",
@@ -2662,7 +2662,7 @@
     "variables": {
       "BIGNUM_BACKEND": "gmp",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-release+no_split_sections",
-      "BROKEN_TESTS": "encoding004 T10458",
+      "BROKEN_TESTS": "encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "release+no_split_sections",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--hash-unit-ids --docs=no-sphinx",
@@ -3647,7 +3647,7 @@
     "variables": {
       "BIGNUM_BACKEND": "gmp",
       "BIN_DIST_NAME": "ghc-x86_64-linux-alpine3_12-validate+fully_static",
-      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458",
+      "BROKEN_TESTS": "ghcilink002 linker_unload_native encoding004 T10458 linker_unload_native",
       "BUILD_FLAVOUR": "validate+fully_static",
       "CONFIGURE_ARGS": "--disable-ld-override ",
       "HADRIAN_ARGS": "--docs=no-sphinx",


=====================================
libraries/base/base.cabal
=====================================
@@ -86,7 +86,7 @@ Library
 
     build-depends:
         rts == 1.0.*,
-        ghc-prim >= 0.5.1.0 && < 0.11,
+        ghc-prim >= 0.5.1.0 && < 0.12,
         ghc-bignum >= 1.0 && < 2.0
 
     exposed-modules:


=====================================
libraries/ghc-bignum/ghc-bignum.cabal
=====================================
@@ -77,7 +77,7 @@ library
     ForeignFunctionInterface
 
   build-depends:
-    ghc-prim >= 0.5.1.0 && < 0.11
+    ghc-prim >= 0.5.1.0 && < 0.12
 
   hs-source-dirs: src/
   include-dirs: include/


=====================================
libraries/ghc-compact/ghc-compact.cabal
=====================================
@@ -39,7 +39,7 @@ library
     UnboxedTuples
     CPP
 
-  build-depends: ghc-prim   >= 0.5.3 && < 0.11,
+  build-depends: ghc-prim   >= 0.5.3 && < 0.12,
                  base       >= 4.9.0 && < 4.20,
                  bytestring >= 0.10.6.0 && <0.12
   ghc-options: -Wall


=====================================
libraries/ghc-heap/ghc-heap.cabal.in
=====================================
@@ -23,7 +23,7 @@ library
   default-language: Haskell2010
 
   build-depends:    base             >= 4.9.0 && < 5.0
-                  , ghc-prim         > 0.2 && < 0.11
+                  , ghc-prim         > 0.2 && < 0.12
                   , rts              == 1.0.*
                   , containers       >= 0.6.2.1 && < 0.7
 


=====================================
libraries/ghc-prim/ghc-prim.cabal
=====================================
@@ -1,6 +1,6 @@
 cabal-version:  2.2
 name:           ghc-prim
-version:        0.10.0
+version:        0.11.0
 -- NOTE: Don't forget to update ./changelog.md
 license:        BSD-3-Clause
 license-file:   LICENSE


=====================================
libraries/ghci/ghci.cabal.in
=====================================
@@ -76,7 +76,7 @@ library
         rts,
         array            == 0.5.*,
         base             >= 4.8 && < 4.20,
-        ghc-prim         >= 0.5.0 && < 0.11,
+        ghc-prim         >= 0.5.0 && < 0.12,
         binary           == 0.8.*,
         bytestring       >= 0.10 && < 0.12,
         containers       >= 0.5 && < 0.7,


=====================================
libraries/text
=====================================
@@ -1 +1 @@
-Subproject commit deaaef6216d3df524f8b998c54b317478094473c
+Subproject commit fe14df3f578cd49cb72555f25c49843a8671dfd2


=====================================
rts/linker/PEi386.c
=====================================
@@ -697,8 +697,16 @@ size_t getSymbolSize ( COFF_HEADER_INFO *info )
     }
 }
 
+// Constants which may be returned by getSymSectionNumber.
+// See https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#section-number-values
+#define PE_SECTION_UNDEFINED ((uint32_t) 0)
+#define PE_SECTION_ABSOLUTE  ((uint32_t) -1)
+#define PE_SECTION_DEBUG     ((uint32_t) -2)
+
+// Returns either PE_SECTION_{UNDEFINED,ABSOLUTE,DEBUG} or the (one-based)
+// section number of the given symbol.
 __attribute__ ((always_inline)) inline
-int32_t getSymSectionNumber ( COFF_HEADER_INFO *info, COFF_symbol* sym )
+uint32_t getSymSectionNumber ( COFF_HEADER_INFO *info, COFF_symbol* sym )
 {
     ASSERT(info);
     ASSERT(sym);
@@ -707,7 +715,13 @@ int32_t getSymSectionNumber ( COFF_HEADER_INFO *info, COFF_symbol* sym )
         case COFF_ANON_BIG_OBJ:
             return sym->ex.SectionNumber;
         default:
-            return sym->og.SectionNumber;
+            // Take care to only sign-extend reserved values; see #22941.
+            switch (sym->og.SectionNumber) {
+                case IMAGE_SYM_UNDEFINED: return PE_SECTION_UNDEFINED;
+                case IMAGE_SYM_ABSOLUTE : return PE_SECTION_ABSOLUTE;
+                case IMAGE_SYM_DEBUG: return PE_SECTION_DEBUG;
+                default: return (uint16_t) sym->og.SectionNumber;
+            }
     }
 }
 
@@ -1652,7 +1666,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
    StgWord globalBssSize = 0;
    for (unsigned int i=0; i < info->numberOfSymbols; i++) {
       COFF_symbol* sym = &oc->info->symbols[i];
-      if (getSymSectionNumber (info, sym) == IMAGE_SYM_UNDEFINED
+      if (getSymSectionNumber (info, sym) == PE_SECTION_UNDEFINED
            && getSymValue (info, sym) > 0
            && getSymStorageClass (info, sym) != IMAGE_SYM_CLASS_SECTION) {
            globalBssSize += getSymValue (info, sym);
@@ -1685,21 +1699,39 @@ ocGetNames_PEi386 ( ObjectCode* oc )
    for (unsigned int i = 0; i < (uint32_t)oc->n_symbols; i++) {
       COFF_symbol* sym = &oc->info->symbols[i];
 
-      int32_t secNumber = getSymSectionNumber (info, sym);
       uint32_t symValue = getSymValue (info, sym);
       uint8_t symStorageClass = getSymStorageClass (info, sym);
-
       SymbolAddr *addr = NULL;
       bool isWeak = false;
       SymbolName *sname = get_sym_name (getSymShortName (info, sym), oc);
-      Section *section = secNumber > 0 ? &oc->sections[secNumber-1] : NULL;
+
+      uint32_t secNumber = getSymSectionNumber (info, sym);
+      Section *section;
+      switch (secNumber) {
+        case PE_SECTION_UNDEFINED:
+          // N.B. This may be a weak symbol
+          section = NULL;
+          break;
+        case PE_SECTION_ABSOLUTE:
+          IF_DEBUG(linker, debugBelch("symbol %s is ABSOLUTE, skipping...\n", sname));
+          i += getSymNumberOfAuxSymbols (info, sym);
+          continue;
+        case PE_SECTION_DEBUG:
+          IF_DEBUG(linker, debugBelch("symbol %s is DEBUG, skipping...\n", sname));
+          i += getSymNumberOfAuxSymbols (info, sym);
+          continue;
+        default:
+          CHECK(secNumber < (uint32_t) oc->n_sections);
+          section = &oc->sections[secNumber-1];
+      }
 
       SymType type;
       switch (getSymType(oc->info->ch_info, sym)) {
       case 0x00: type = SYM_TYPE_DATA; break;
       case 0x20: type = SYM_TYPE_CODE; break;
       default:
-          debugBelch("Invalid symbol type: 0x%x\n", getSymType(oc->info->ch_info, sym));
+          debugBelch("Symbol %s has invalid type 0x%x\n",
+                     sname, getSymType(oc->info->ch_info, sym));
           return 1;
       }
 
@@ -1730,8 +1762,18 @@ ocGetNames_PEi386 ( ObjectCode* oc )
           CHECK(symValue == 0);
           COFF_symbol_aux_weak_external *aux = (COFF_symbol_aux_weak_external *) (sym+1);
           COFF_symbol* targetSym = &oc->info->symbols[aux->TagIndex];
-          int32_t targetSecNumber = getSymSectionNumber (info, targetSym);
-          Section *targetSection = targetSecNumber > 0 ? &oc->sections[targetSecNumber-1] : NULL;
+
+          uint32_t targetSecNumber = getSymSectionNumber (info, targetSym);
+          Section *targetSection;
+          switch (targetSecNumber) {
+            case PE_SECTION_UNDEFINED:
+            case PE_SECTION_ABSOLUTE:
+            case PE_SECTION_DEBUG:
+              targetSection = NULL;
+              break;
+            default:
+              targetSection = &oc->sections[targetSecNumber-1];
+          }
           addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym));
       }
       else if (  secNumber == IMAGE_SYM_UNDEFINED && symValue > 0) {
@@ -1850,6 +1892,9 @@ ocGetNames_PEi386 ( ObjectCode* oc )
                return false;
 
           break;
+      } else if (secNumber == PE_SECTION_UNDEFINED) {
+          IF_DEBUG(linker, debugBelch("symbol %s is UNDEFINED, skipping...\n", sname));
+          i += getSymNumberOfAuxSymbols (info, sym);
       }
 
       if ((addr != NULL || isWeak)
@@ -1976,7 +2021,19 @@ ocResolve_PEi386 ( ObjectCode* oc )
                   debugBelch("'\n" ));
 
          if (getSymStorageClass (info, sym) == IMAGE_SYM_CLASS_STATIC) {
-            Section section = oc->sections[getSymSectionNumber (info, sym)-1];
+            uint32_t sect_n = getSymSectionNumber (info, sym);
+            switch (sect_n) {
+                case PE_SECTION_UNDEFINED:
+                case PE_SECTION_ABSOLUTE:
+                case PE_SECTION_DEBUG:
+                    errorBelch(" | %" PATH_FMT ": symbol `%s' has invalid section number %02x",
+                               oc->fileName, symbol, sect_n);
+                    return false;
+                default:
+                    break;
+            }
+            CHECK(sect_n < (uint32_t) oc->n_sections);
+            Section section = oc->sections[sect_n - 1];
             S = ((size_t)(section.start))
               + ((size_t)(getSymValue (info, sym)));
          } else {


=====================================
rts/linker/PEi386.h
=====================================
@@ -143,7 +143,7 @@ struct _Alignments {
 COFF_OBJ_TYPE getObjectType ( char* image, pathchar* fileName );
 COFF_HEADER_INFO* getHeaderInfo ( ObjectCode* oc );
 size_t getSymbolSize ( COFF_HEADER_INFO *info );
-int32_t getSymSectionNumber ( COFF_HEADER_INFO *info, COFF_symbol* sym );
+uint32_t getSymSectionNumber ( COFF_HEADER_INFO *info, COFF_symbol* sym );
 uint32_t getSymValue ( COFF_HEADER_INFO *info, COFF_symbol* sym );
 uint8_t getSymStorageClass ( COFF_HEADER_INFO *info, COFF_symbol* sym );
 uint8_t getSymNumberOfAuxSymbols ( COFF_HEADER_INFO *info, COFF_symbol* sym );



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f9ef5a44e54073854571a8b421e64e63706e4572...f2f16867e8912e52a0f3f5492c7f30eeb6d444b5

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f9ef5a44e54073854571a8b421e64e63706e4572...f2f16867e8912e52a0f3f5492c7f30eeb6d444b5
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/20230727/902c7bcb/attachment-0001.html>


More information about the ghc-commits mailing list