wasm: Remove PIC guards from Wasm.S#142
Open
angerman wants to merge 2 commits intostable-ghc-9.14from
Open
Conversation
Author
|
This reverts ghc@98a32ec. |
Author
|
This seems to originate from #134 |
Author
|
This change is somehow part of #140, where it most certainly does not belong to. |
This commit teaches GHC's internal package representation (UnitInfo)
about package data directories, enabling the compiler to properly find
files installed via Cabal's data-files mechanism.
Background:
-----------
Previously, while Cabal's InstalledPackageInfo includes dataDir, and
this field appears in package .conf files, it was intentionally filtered
out during conversion to GHC's internal DbUnitInfo format. The compiler's
UnitInfo type didn't expose data directories because compilers typically
don't need them.
However, certain backends may need to access data files during compilation
or linking. This commit adds proper support for exposing data directories
to the compiler.
Changes:
--------
1. libraries/ghc-boot/GHC/Unit/Database.hs:
- Add unitDataDir :: Maybe FilePathST field to GenericUnitInfo
- Update Binary instance (put/get) to serialize the field
- Update mungeUnitInfoPaths to handle ${pkgroot} variable substitution
- Add documentation explaining the field's purpose
2. utils/ghc-pkg/Main.hs:
- Stop filtering out dataDir in convertPackageInfoToCacheFormat
- Convert Cabal's dataDir to GHC's unitDataDir (Nothing if empty)
Benefits:
---------
- Uses Cabal's data-files mechanism as intended
- Discoverable through package metadata (not hardcoded paths)
- Future-proof: enables any package's compiler code to access data files
- Standard path munging for relocatable installs via ${pkgroot}
Note: This breaks binary package cache format - caches will be rebuilt
on next GHC build.
This commit implements support for WASM's GlobalRegs pattern where global registers are defined in a separate assembly file that's compiled on-demand during executable linking, rather than being statically linked into the RTS. Changes: -------- 1. rts/wasm/Wasm.S: - Remove PIC (#ifdef PIC) guards that were preventing WASM builds - WASM doesn't use position-independent code in the traditional sense - Clean up assembly to work correctly for WASM architecture 2. rts/wasm/WasmGlobalRegs.S (NEW): - Extract GlobalRegs definitions into a separate file - Contains WASM-specific global register declarations - Will be compiled on-demand during executable linking - Installed via rts.cabal data-files mechanism 3. rts/rts.cabal: - Add wasm/WasmGlobalRegs.S to data-files - Makes the file available for compiler access during linking - See Note [WASM GlobalRegs Linking] for rationale 4. compiler/GHC/Linker/Executable.hs: - Add mkWasmGlobalRegsObj function for on-demand compilation - Searches for WasmGlobalRegs.S via unitDataDir (primary path) - Falls back to library-relative and source tree paths - Compiles to temporary object file during executable linking - Includes comprehensive error reporting if file not found - Add import for GHC.Data.ShortText and noSrcSpan 5. compiler/GHC/Platform/Ways.hs: - Update WASM way definition to handle GlobalRegs differently - Fix module import cycle by adjusting imports - Add reference to mkWasmGlobalRegsObj for documentation Architecture: ------------- The WASM backend requires GlobalRegs to be compiled separately per executable rather than being part of the RTS library. This is because: - WASM has specific requirements for global register handling - Each executable needs its own GlobalRegs object - Cannot be statically linked into the RTS The linker now: 1. Detects WASM architecture during executable linking 2. Locates WasmGlobalRegs.S via package metadata (unitDataDir) 3. Compiles it on-demand to a temporary object file 4. Includes it in the final link This uses the new unitDataDir support to properly find the file via Cabal's data-files mechanism rather than hardcoded path assumptions.
6cd43f7 to
e156b65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes
#if !defined(__PIC__)guards from rts/wasm/Wasm.S.These guards were added to prevent building predefined GlobalRegs for WASM PIC mode (due to dylink limitations with relocatable wasm globals). After disabling tables-next-to-code for stage3 WASM builds, the guards are no longer needed.
Related: commit 7210be4 "Fix build of WASM"