GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-05-23T20:39:01Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/23011$ORIGIN is not what it appears2023-05-23T20:39:01ZGreg Steuck$ORIGIN is not what it appears## Summary
A ton of tests broke on OpenBSD on aa3a262d15.
## Steps to reproduce
Commit aa3a262d15 merged in !9767 is detrimental on OpenBSD. The first
symptom is a ton of tests are failing with the likes of:
```
Wrong exit code for C...## Summary
A ton of tests broke on OpenBSD on aa3a262d15.
## Steps to reproduce
Commit aa3a262d15 merged in !9767 is detrimental on OpenBSD. The first
symptom is a ton of tests are failing with the likes of:
```
Wrong exit code for CountDepsParser()(expected 0 , actual 2 )
Stderr ( CountDepsParser ):
ld.so: count-deps: can't load library 'libHSunix-2.8.0.0-ghc9.7.20230221.so'
```
The binaries are weirdly broken now, they work fine from stage1 but
they fail when invoked from a sym-linked location, i.e. test/bin.
E.g.
```
% ldd ./_validatebuild/test/bin/check-exact
./_validatebuild/test/bin/check-exact:
ld.so: check-exact: can't load library 'libHStime-1.12.2-ghc9.7.20230221.so'
./_validatebuild/test/bin/check-exact: signal 9
% ./_validatebuild/test/bin/check-exact
ld.so: check-exact: can't load library 'libHSexceptions-0.10.7-ghc9.7.20230221.so'
[1] 28192 killed ./_validatebuild/test/bin/check-exact
% ./_validatebuild/stage1/bin/check-exact
Missing file: /home/alanz/mysrc/git.haskell.org/worktree/master/_build/stage1/lib/settings
% readelf --dynamic ./_validatebuild/stage1/bin/check-exact | grep RUNPATH
0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../lib/x86_64-openbsd-ghc-9.7.20230221:$ORIGIN/../../../lib/x86_64-openbsd-ghc-9.7.20230221]
% ls -l ./_validatebuild/test/bin/check-exact
lrwxr-xr-x 1 greg greg 61 Feb 20 20:01 ./_validatebuild/test/bin/check-exact -> /home/greg/s/ghc-broken/_validatebuild/stage1/bin/check-exact
% ls -l ./_validatebuild/test/lib
ls: ./_validatebuild/test/lib: No such file or directory
```
When I build at the commit before this change I get a much more
verbose RUNPATH which works fine when the binary is symlinked into
test/bin.
```
% readelf --dynamic ghc/_validatebuild/test/bin/check-exact | grep RUNP
0x000000000000001d (RUNPATH) Library runpath: [/home/greg/s/ghc/_validatebuild/stage1/inplace/../compiler/build:...
```
The semantics of $ORIGIN is not covered by any standard I know of. If
I read the [Linux manual
page](https://man7.org/linux/man-pages/man8/ld.so.8.html) literally,
the behavior of OpenBSD ld.so is not errant:
> $ORIGIN (or equivalently ${ORIGIN})
> This expands to the directory containing the program or
> shared object. Thus, an application located in
> somedir/app could be compiled with
>
> gcc -Wl,-rpath,'$ORIGIN/../lib'
>
> so that it finds an associated shared object in
> somedir/lib no matter where somedir is located in the
> directory hierarchy. This facilitates the creation of
> "turn-key" applications that do not need to be installed
> into special directories, but can instead be unpacked into
> any directory and still find their own shared objects.
The symlinked `test/bin` location does *NOT* have a corresponding
`test/lib` where `$ORIGIN` points at. Apparently other implementations
resolve `$ORIGIN` relative to the symlink pointee.
## Environment
* GHC version used: aa3a262d15
Optional:
* Operating System: OpenBSD
* System Architecture: amd64
FYI @PHOGreg SteuckGreg Steuckhttps://gitlab.haskell.org/ghc/ghc/-/issues/20635Failure of hadrian stage1 libffi: Needed "_validatebuild/stage1/rts/build/lib...2022-09-25T19:14:58ZGreg SteuckFailure of hadrian stage1 libffi: Needed "_validatebuild/stage1/rts/build/libffi.so.9.0" which is not any of libffi's built shared libraries: ["_validatebuild/stage1/libffi/build/inst/lib/libffi.so.9.0"]## Summary
Hadrian build fails on OpenBSD:
```
| ContextData oracle: resolving data for 'ghc' (Stage1, v)...
# _validatebuild/stage1/compiler/setup-config
# _validatebuild/stage0/utils/haddock/build/Documentation/Haddock.o
# _validatebu...## Summary
Hadrian build fails on OpenBSD:
```
| ContextData oracle: resolving data for 'ghc' (Stage1, v)...
# _validatebuild/stage1/compiler/setup-config
# _validatebuild/stage0/utils/haddock/build/Documentation/Haddock.o
# _validatebuild/stage0/utils/haddock/build/Main.o
# _validatebuild/stage0/utils/haddock/build/Documentation/Haddock.o _validatebuild/stage0/utils/haddock/build/Documentation/Haddock.hi
# _validatebuild/stage0/utils/haddock/build/Main.o _validatebuild/stage0/utils/haddock/build/Main.hi
# _validatebuild/stage0/utils/haddock/build/Documentation/Haddock.hi
# _validatebuild/stage1/rts/build/libCffi_thr_l.a
# _validatebuild/stage1/rts/build/libCffi_thr_debug.a
# _validatebuild/stage1/rts/build/libCffi_l.a
# _validatebuild/stage1/rts/build/libCffi_debug.a
# _validatebuild/stage1/rts/build/libCffi_thr.a
# _validatebuild/stage1/rts/build/libCffi.a
# _validatebuild/stage1/rts/build/libffi.so.9.0
Error when running Shake build system:
at action, called at src/Rules.hs:39:19 in main:Rules
at need, called at src/Rules.hs:61:5 in main:Rules
* Depends on: _validatebuild/stage1/lib/package.conf.d/ghc-prim-0.8.0.conf
at apply1, called at src/Development/Shake/Internal/Rules/Oracle.hs:159:32 in shake-0.19.4-956df6a960f412f043f5c30515a600878ff928d4342dfe8839afc8448494863c:Development.Shake.Internal.Rules.Oracle
* Depends on: OracleQ (ContextDataKey (Context {stage = Stage1, package = Package {pkgType = Library, pkgName = "ghc-prim", pkgPath = "libraries/ghc-prim"}, way = v}))
at need, called at src/Hadrian/Oracles/Cabal/Rules.hs:54:9 in main:Hadrian.Oracles.Cabal.Rules
* Depends on: _validatebuild/stage1/libraries/ghc-prim/setup-config
at need, called at src/Rules/Library.hs:164:18 in main:Rules.Library
* Depends on: _validatebuild/stage1/rts/build/libffi.so.9.0
at error, called at src/Rules/Rts.hs:77:18 in main:Rules.Rts
* Raised the exception:
Needed "_validatebuild/stage1/rts/build/libffi.so.9.0" which is not any of libffi's built shared libraries: ["_validatebuild/stage1/libffi/build/inst/lib/libffi.so.9.0"]
Build failed.
```
## Steps to reproduce
I'm using this patched tree (https://gitlab.haskell.org/blackgnezdo/ghc/-/commit/93b01c3d691ec614fe09b373d43809fa91e37b47) to avoid #18173. I start the build and it fails with diagnostics above.
```
ulimit -d $((10<<20)); AUTOCONF_VERSION=2.71 AUTOMAKE_VERSION=1.16 ./validate --build-only
```
These are the only files to choose from, note the absence of `*.so` (which is normal on OpenBSD):
```
% ls -l _validatebuild/stage1/libffi/build/inst/lib/
total 368
-rw-r--r-- 1 greg wsrc 92662 Nov 7 11:55 libffi.a
-rwxr-xr-x 1 greg wsrc 947 Nov 7 11:55 libffi.la
-rwxr-xr-x 1 greg wsrc 65856 Nov 7 11:55 libffi.so.9.0
drwxr-xr-x 2 greg wsrc 512 Nov 7 11:55 pkgconfig
```
I suspect hadrian/src/Rules/Rts.hs needs to adapt as this is unlikely to work given the files above:
```
buildPath -/- "libffi*.so*" %> copyLibffiDynamicUnix stage ".so"
```
## Expected behavior
Build goes all the way.
## Environment
* GHC version used: 8.10.6
Optional:
* Operating System: OpenBSD 7.0-current
* System Architecture: amd64https://gitlab.haskell.org/ghc/ghc/-/issues/22174system-cxx-std-lib: Add support for FreeBSD libcxxrt doesn't work on OpenBSD2022-09-25T19:03:49ZMatthew Pickeringsystem-cxx-std-lib: Add support for FreeBSD libcxxrt doesn't work on OpenBSD@blackgnezdo reports:
Sadly, this is not working on OpenBSD (whereas the previous version did). A fix which makes `configure` succeed would be to add:
```
diff --git a/m4/fp_find_cxx_std_lib.m4 b/m4/fp_find_cxx_std_lib.m4
index 24f78d0a...@blackgnezdo reports:
Sadly, this is not working on OpenBSD (whereas the previous version did). A fix which makes `configure` succeed would be to add:
```
diff --git a/m4/fp_find_cxx_std_lib.m4 b/m4/fp_find_cxx_std_lib.m4
index 24f78d0a6f..09f4524d89 100644
--- a/m4/fp_find_cxx_std_lib.m4
+++ b/m4/fp_find_cxx_std_lib.m4
@@ -75,6 +75,7 @@ EOF
case $CXX_STD_LIB_FLAVOUR in
c++)
try_libs "-lc++ -lc++abi" "libc++.so" "c++ c++abi" || \
+ try_libs "-lc++ -lc++abi -lpthread" "libc++.so" "c++ c++abi pthread" || \
try_libs "-lc++ -lcxxrt" "libc++.so" "c++ cxxrt" ||
AC_MSG_ERROR([Failed to find C++ standard library]) ;;
stdc++)
```
but I'm uncertain if it's a great idea to effectively replicate some behaviors [baked into platform-dependent clang code](https://github.com/openbsd/src/blob/a0747c9f67a4ae71ccb71e62a28d1ea19e06a63c/gnu/llvm/clang/lib/Driver/ToolChains/OpenBSD.cpp#L305-L307).9.4.3Ben GamariBen Gamarihttps://gitlab.haskell.org/ghc/ghc/-/issues/21836CXX_STD_LIB_LIBS should surface in testsuite2022-07-15T12:11:52ZGreg SteuckCXX_STD_LIB_LIBS should surface in testsuite## Summary
Some tests (e.g. T13366Cxx) rely on `config.stdcxx_impl` which is currently not set to the values determined by cofigure tests responsible for setting `CXX_STD_LIB_LIBS`. Instead the value of `stdcxx_impl` defaults to `stdc++...## Summary
Some tests (e.g. T13366Cxx) rely on `config.stdcxx_impl` which is currently not set to the values determined by cofigure tests responsible for setting `CXX_STD_LIB_LIBS`. Instead the value of `stdcxx_impl` defaults to `stdc++` with a tweak in `testsuite/config/ghc` which replaces the value with:
```
if windows:
config.supports_dynamic_hs = False
config.stdcxx_impl = 'c++'
```
## Steps to reproduce
`T13366Cxx` test fails on OpenBSD:
```
<command line>: user specified .o/.so/.DLL could not be loaded (File not found)
Whilst trying to load: (dynamic) stdc++
Additional directories searched: (none)
```
## Expected behavior
Once `CXX_STD_LIB_LIBS` get propagated into the testsuite the correct libraries will be easy to use. There's a minor twist, the libraries should be a list whereas `config.stdcxx_impl` is a singleton string.
A couple of tests (e.g. `ghcilink006`, `ghcilink003`) use `LIBCXX` make variable which is copied from `config.stdcxx_impl`, so they should also be updated.
## Environment
* GHC version used: 460505345e
Optional:
* Operating System: OpenBSD
* System Architecture: amd64Ben GamariBen Gamarihttps://gitlab.haskell.org/ghc/ghc/-/issues/21155NativeAmd64Asm: ld.lld: error: can't create dynamic relocation R_X86_64_64 ag...2022-03-26T17:38:23ZGreg SteuckNativeAmd64Asm: ld.lld: error: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segmentI suspect something in the recent adjustors work by @bgamari went sideways. At least my usual HEAD-building OpenBSD recipe started failing with:
```
"rm" -f rts/dist-install/build/libHSrts-ghc9.3.20220301.so
"inplace/bin/ghc-stage1" -th...I suspect something in the recent adjustors work by @bgamari went sideways. At least my usual HEAD-building OpenBSD recipe started failing with:
```
"rm" -f rts/dist-install/build/libHSrts-ghc9.3.20220301.so
"inplace/bin/ghc-stage1" -this-unit-id rts -shared -dynamic -dynload deploy -no-auto-link-packages `cat rts/dist-install/libs.depend` rts/dist-install/build/Adjustor.dyn_o rts/dist-install/build/Arena.dyn_o rts/dist-install/build/Capability.dyn_o rts/dist-install/build/CheckUnload.dyn_o rts/dist-install/build/CloneStack.dyn_o rts/dist-install/build/ClosureFlags.dyn_o rts/dist-install/build/ClosureSize.dyn_o rts/dist-install/build/Disassembler.dyn_o rts/dist-install/build/ExecPage.dyn_o rts/dist-install/build/FileLock.dyn_o rts/dist-install/build/ForeignExports.dyn_o rts/dist-install/build/Globals.dyn_o rts/dist-install/build/Hash.dyn_o rts/dist-install/build/Heap.dyn_o rts/dist-install/build/Hpc.dyn_o rts/dist-install/build/HsFFI.dyn_o rts/dist-install/build/IOManager.dyn_o rts/dist-install/build/IPE.dyn_o rts/dist-install/build/Inlines.dyn_o rts/dist-install/build/Interpreter.dyn_o rts/dist-install/build/LdvProfile.dyn_o rts/dist-install/build/Libdw.dyn_o rts/dist-install/build/LibdwPool.dyn_o rts/dist-install/build/Linker.dyn_o rts/dist-install/build/Messages.dyn_o rts/dist-install/build/OldARMAtomic.dyn_o rts/dist-install/build/PathUtils.dyn_o rts/dist-install/build/Pool.dyn_o rts/dist-install/build/Printer.dyn_o rts/dist-install/build/ProfHeap.dyn_o rts/dist-install/build/ProfilerReport.dyn_o rts/dist-install/build/ProfilerReportJson.dyn_o rts/dist-install/build/Profiling.dyn_o rts/dist-install/build/Proftimer.dyn_o rts/dist-install/build/RaiseAsync.dyn_o rts/dist-install/build/ReportMemoryMap.dyn_o rts/dist-install/build/RetainerProfile.dyn_o rts/dist-install/build/RetainerSet.dyn_o rts/dist-install/build/RtsAPI.dyn_o rts/dist-install/build/RtsDllMain.dyn_o rts/dist-install/build/RtsFlags.dyn_o rts/dist-install/build/RtsMain.dyn_o rts/dist-install/build/RtsMessages.dyn_o rts/dist-install/build/RtsStartup.dyn_o rts/dist-install/build/RtsSymbolInfo.dyn_o rts/dist-install/build/RtsSymbols.dyn_o rts/dist-install/build/RtsUtils.dyn_o rts/dist-install/build/STM.dyn_o rts/dist-install/build/Schedule.dyn_o rts/dist-install/build/Sparks.dyn_o rts/dist-install/build/SpinLock.dyn_o rts/dist-install/build/StableName.dyn_o rts/dist-install/build/StablePtr.dyn_o rts/dist-install/build/StaticPtrTable.dyn_o rts/dist-install/build/Stats.dyn_o rts/dist-install/build/StgCRun.dyn_o rts/dist-install/build/StgPrimFloat.dyn_o rts/dist-install/build/Task.dyn_o rts/dist-install/build/ThreadLabels.dyn_o rts/dist-install/build/ThreadPaused.dyn_o rts/dist-install/build/Threads.dyn_o rts/dist-install/build/Ticky.dyn_o rts/dist-install/build/Timer.dyn_o rts/dist-install/build/TopHandler.dyn_o rts/dist-install/build/Trace.dyn_o rts/dist-install/build/TraverseHeap.dyn_o rts/dist-install/build/TraverseHeapTest.dyn_o rts/dist-install/build/WSDeque.dyn_o rts/dist-install/build/Weak.dyn_o rts/dist-install/build/fs.dyn_o rts/dist-install/build/hooks/FlagDefaults.dyn_o rts/dist-install/build/hooks/LongGCSync.dyn_o rts/dist-install/build/hooks/MallocFail.dyn_o rts/dist-install/build/hooks/OnExit.dyn_o rts/dist-install/build/hooks/OutOfHeap.dyn_o rts/dist-install/build/hooks/StackOverflow.dyn_o rts/dist-install/build/sm/BlockAlloc.dyn_o rts/dist-install/build/sm/CNF.dyn_o rts/dist-install/build/sm/Compact.dyn_o rts/dist-install/build/sm/Evac.dyn_o rts/dist-install/build/sm/Evac_thr.dyn_o rts/dist-install/build/sm/GC.dyn_o rts/dist-install/build/sm/GCAux.dyn_o rts/dist-install/build/sm/GCUtils.dyn_o rts/dist-install/build/sm/MBlock.dyn_o rts/dist-install/build/sm/MarkWeak.dyn_o rts/dist-install/build/sm/NonMoving.dyn_o rts/dist-install/build/sm/NonMovingCensus.dyn_o rts/dist-install/build/sm/NonMovingMark.dyn_o rts/dist-install/build/sm/NonMovingScav.dyn_o rts/dist-install/build/sm/NonMovingShortcut.dyn_o rts/dist-install/build/sm/NonMovingSweep.dyn_o rts/dist-install/build/sm/Sanity.dyn_o rts/dist-install/build/sm/Scav.dyn_o rts/dist-install/build/sm/Scav_thr.dyn_o rts/dist-install/build/sm/Storage.dyn_o rts/dist-install/build/sm/Sweep.dyn_o rts/dist-install/build/eventlog/EventLog.dyn_o rts/dist-install/build/eventlog/EventLogWriter.dyn_o rts/dist-install/build/linker/CacheFlush.dyn_o rts/dist-install/build/linker/Elf.dyn_o rts/dist-install/build/linker/LoadArchive.dyn_o rts/dist-install/build/linker/M32Alloc.dyn_o rts/dist-install/build/linker/MMap.dyn_o rts/dist-install/build/linker/MachO.dyn_o rts/dist-install/build/linker/PEi386.dyn_o rts/dist-install/build/linker/SymbolExtras.dyn_o rts/dist-install/build/linker/elf_got.dyn_o rts/dist-install/build/linker/elf_plt.dyn_o rts/dist-install/build/linker/elf_plt_aarch64.dyn_o rts/dist-install/build/linker/elf_plt_arm.dyn_o rts/dist-install/build/linker/elf_reloc.dyn_o rts/dist-install/build/linker/elf_reloc_aarch64.dyn_o rts/dist-install/build/linker/elf_tlsgd.dyn_o rts/dist-install/build/linker/elf_util.dyn_o rts/dist-install/build/linker/macho/plt.dyn_o rts/dist-install/build/linker/macho/plt_aarch64.dyn_o rts/dist-install/build/posix/GetEnv.dyn_o rts/dist-install/build/posix/GetTime.dyn_o rts/dist-install/build/posix/OSMem.dyn_o rts/dist-install/build/posix/OSThreads.dyn_o rts/dist-install/build/posix/Select.dyn_o rts/dist-install/build/posix/Signals.dyn_o rts/dist-install/build/posix/TTY.dyn_o rts/dist-install/build/posix/Ticker.dyn_o rts/dist-install/build/adjustor/AdjustorPool.dyn_o rts/dist-install/build/adjustor/NativeAmd64.dyn_o rts/dist-install/build/StgCRunAsm.dyn_o rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o rts/dist-install/build/Apply.dyn_o rts/dist-install/build/Compact.dyn_o rts/dist-install/build/Exception.dyn_o rts/dist-install/build/HeapStackCheck.dyn_o rts/dist-install/build/PrimOps.dyn_o rts/dist-install/build/StgMiscClosures.dyn_o rts/dist-install/build/StgStartup.dyn_o rts/dist-install/build/StgStdThunks.dyn_o rts/dist-install/build/Updates.dyn_o rts/dist-install/build/AutoApply.dyn_o -optl-Wl,-z -optl-Wl,wxneeded -fPIC -dynamic -O0 -H64m -Wall -fllvm-fill-undef-with-garbage -Werror -this-unit-id rts -dcmm-lint -package-env - -i -irts -irts/dist-install/build -Irts/dist-install/build -irts/dist-install/build/./autogen -Irts/dist-install/build/./autogen -Irts/include/../dist-install/build/include -Irts/include/. -Irts/. -optP-DCOMPILING_RTS -optP-DFS_NAMESPACE=rts -O2 -Wcpp-undef -Wnoncanonical-monad-instances -fno-use-rpaths -optl-Wl,-zorigin -o rts/dist-install/build/libHSrts-ghc9.3.20220301.so
ld.lld: error: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o
>>> referenced by NativeAmd64Asm.S
>>> rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o:(.text+0x50)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
`cc' failed in phase `Linker'. (Exit code: 1)
gmake[1]: *** [rts/ghc.mk:353: rts/dist-install/build/libHSrts-ghc9.3.20220301.so] Error 1
gmake: *** [Makefile:128: all] Error 2
```
The file indeed has an R_X86_64_64 relocation:
```
% "inplace/bin/ghc-stage1" -optc--target=x86_64-unknown-openbsd -optc-Wall -optc-Werror -optc-Wall -optc-Wextra -optc-Wstrict-prototypes -optc-Wmissing-prototypes -optc-Wmissing-declarations -optc-Winline -optc-Wpointer-arith -optc-Wmissing-noreturn -optc-Wnested-externs -optc-Wredundant-decls -optc-Wno-aggregate-return -optc-Wno-unused-label -optc-fno-strict-aliasing -optc-fno-common -optc-Irts/dist-install/build/./autogen -optc-Irts/include/../dist-install/build/include -optc-Irts/include/. -optc-Irts/. -optc-DCOMPILING_RTS -optc-DFS_NAMESPACE=rts -optc-Wno-unknown-pragmas -optc-O2 -optc-fomit-frame-pointer -optc-g -optc-DDYNAMIC -optc-DRtsWay=\"rts_dyn\" -fPIC -dynamic -O0 -H64m -Wall -fllvm-fill-undef-with-garbage -Werror -this-unit-id rts -dcmm-lint -package-env - -i -irts -irts/dist-install/build -Irts/dist-install/build -irts/dist-install/build/./autogen -Irts/dist-install/build/./autogen -Irts/include/../dist-install/build/include -Irts/include/. -Irts/. -optP-DCOMPILING_RTS -optP-DFS_NAMESPACE=rts -O2 -Wcpp-undef -Wnoncanonical-monad-instances -c rts/adjustor/NativeAmd64Asm.S -o rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o
% file rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o
rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o: ELF 64-bit LSB relocatable, x86-64, version 1
% objdump -r rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o
rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o: file format elf64-x86-64
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000000000000050 R_X86_64_64 .text+0x0000000000000060
```
Doing a naive monkey-see-monkey-do doesn't help:
```
% git diff rts/adjustor/NativeAmd64Asm.S
diff --git a/rts/adjustor/NativeAmd64Asm.S b/rts/adjustor/NativeAmd64Asm.S
index 32e8da50fd..7c4444d46e 100644
--- a/rts/adjustor/NativeAmd64Asm.S
+++ b/rts/adjustor/NativeAmd64Asm.S
@@ -14,7 +14,7 @@
CSYM(x):
-#if defined(darwin_HOST_OS)
+#if defined(darwin_HOST_OS) || defined(openbsd_HOST_OS)
/*
* Note [Adjustor templates live in data section on Darwin]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -84,7 +84,7 @@ lcl_complex_ccall_adjustor_context: // See Note [Adjustors: Local symbol referen
DECLARE_CSYM(complex_ccall_adjustor_end)
-#if defined(darwin_HOST_OS)
+#if defined(darwin_HOST_OS) || defined(openbsd_HOST_OS)
/* See Note [Adjustor templates live in data section on Darwin]. */
.section __TEXT,__text
#endif
% "inplace/bin/ghc-stage1" -optc--target=x86_64-unknown-openbsd -optc-Wall -optc-Werror -optc-Wall -optc-Wextra -optc-Wstrict-prototypes -optc-Wmissing-prototypes -optc-Wmissing-declarations -optc-Winline -optc-Wpointer-arith -optc-Wmissing-noreturn -optc-Wnested-externs -optc-Wredundant-decls -optc-Wno-aggregate-return -optc-Wno-unused-label -optc-fno-strict-aliasing -optc-fno-common -optc-Irts/dist-install/build/./autogen -optc-Irts/include/../dist-install/build/include -optc-Irts/include/. -optc-Irts/. -optc-DCOMPILING_RTS -optc-DFS_NAMESPACE=rts -optc-Wno-unknown-pragmas -optc-O2 -optc-fomit-frame-pointer -optc-g -optc-DDYNAMIC -optc-DRtsWay=\"rts_dyn\" -fPIC -dynamic -O0 -H64m -Wall -fllvm-fill-undef-with-garbage -Werror -this-unit-id rts -dcmm-lint -package-env - -i -irts -irts/dist-install/build -Irts/dist-install/build -irts/dist-install/build/./autogen -Irts/dist-install/build/./autogen -Irts/include/../dist-install/build/include -Irts/include/. -Irts/. -optP-DCOMPILING_RTS -optP-DFS_NAMESPACE=rts -O2 -Wcpp-undef -Wnoncanonical-monad-instances -c rts/adjustor/NativeAmd64Asm.S -o rts/dist-install/build/adjustor/NativeAmd64Asm.dyn_o
rts/adjustor/NativeAmd64Asm.S:29:17: error:
error: expected string in directive
|
29 | .section __DATA,__data
| ^
.section __DATA,__data
^
rts/adjustor/NativeAmd64Asm.S:89:17: error:
error: expected string in directive
|
89 | .section __TEXT,__text
| ^
.section __TEXT,__text
^
`cc' failed in phase `Assembler'. (Exit code: 1)
%
```9.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/20734internal error: m32_alloc_page: failed to get allocation in lower 32-bits2022-02-10T02:40:59ZGreg Steuckinternal error: m32_alloc_page: failed to get allocation in lower 32-bits## Summary
ghc --interactive aborts with message in the title.
## Steps to reproduce
```
% ./inplace/bin/ghc-stage2 --interactive
GHCi, version 9.3.20211124: https://www.haskell.org/ghc/ :? for help
ghc-stage2: internal error: m32_all...## Summary
ghc --interactive aborts with message in the title.
## Steps to reproduce
```
% ./inplace/bin/ghc-stage2 --interactive
GHCi, version 9.3.20211124: https://www.haskell.org/ghc/ :? for help
ghc-stage2: internal error: m32_alloc_page: failed to get allocation in lower 32-bits
(GHC version 9.3.20211124 for x86_64_unknown_openbsd)
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
```
gdb stack trace (not that it's particularly mysterious):
```
(gdb) bt
#0 thrkill () at /tmp/-:3
#1 0x00000002ed8fc80e in _libc_abort () at /usr/src/lib/libc/stdlib/abort.c:51
#2 0x000000023eb2fdd8 in rtsFatalInternalErrorFn (s=0x23eb08e06 "m32_alloc_page: failed to get allocation in lower 32-bits",
ap=0x7f7ffffc4ad0) at /home/greg/s/ghc/rts/RtsMessages.c:186
#3 0x000000023eb2ffe2 in barf (s=0x0) at /home/greg/s/ghc/rts/RtsMessages.c:48
#4 0x000000023eb6b55c in m32_alloc_page () at rts/linker/M32Alloc.c:250
#5 m32_alloc (alloc=0x2e9987e00, size=<optimized out>, alignment=<optimized out>) at rts/linker/M32Alloc.c:441
#6 0x000000023eb6b683 in ocAllocateExtras (oc=0x2e9998700, count=<optimized out>, first=0, bssSize=0)
at rts/linker/SymbolExtras.c:104
#7 0x000000023eb27a84 in loadOc (oc=0x2e9998700) at /home/greg/s/ghc/rts/Linker.c:1740
#8 0x000000023eb6ab48 in loadArchive_ (path=0x26db1a510 "/usr/local/lib/libgmp.a") at rts/linker/LoadArchive.c:535
#9 loadArchive (path=0x26db1a510 "/usr/local/lib/libgmp.a") at rts/linker/LoadArchive.c:629
#10 0x00000002bcab6059 in ?? () from /home/greg/s/ghc/libraries/ghci/dist-install/build/libHSghci-9.3-ghc9.3.20211124.so
```
ktrace (syscall trace) reveals this:
```
52253 ghc-stage2 CALL mmap(0x40000000,0x1000,0x3<PROT_READ|PROT_WRITE>,0x1002<MAP_PRIVATE|MAP_ANON>,-1,0)
52253 ghc-stage2 RET mmap 1073741824/0x40000000
52253 ghc-stage2 CALL mmap(0,0x2000,0x3<PROT_READ|PROT_WRITE>,0x1002<MAP_PRIVATE|MAP_ANON>,-1,0)
52253 ghc-stage2 RET mmap 9112080384/0x21f1f5000
52253 ghc-stage2 CALL kbind(0x7f7fffff48f8,24,0x2f81bae1abf0c0d7)
52253 ghc-stage2 RET kbind 0
52253 ghc-stage2 CALL mmap(0,0x3000,0x3<PROT_READ|PROT_WRITE>,0x1002<MAP_PRIVATE|MAP_ANON>,-1,0)
52253 ghc-stage2 RET mmap 9471471616/0x2348b3000
52253 ghc-stage2 CALL mmap(0,0x2000,0x3<PROT_READ|PROT_WRITE>,0x1002<MAP_PRIVATE|MAP_ANON>,-1,0)
52253 ghc-stage2 RET mmap 11532533760/0x2af648000
52253 ghc-stage2 CALL mmap(0x40000000,0x20000,0x3<PROT_READ|PROT_WRITE>,0x1002<MAP_PRIVATE|MAP_ANON>,-1,0)
52253 ghc-stage2 RET mmap 8593272832/0x20032f000
52253 ghc-stage2 CALL kbind(0x7f7fffff4728,24,0x2f81bae1abf0c0d7)
52253 ghc-stage2 RET kbind 0
52253 ghc-stage2 CALL write(2,0x7f7fffff3f40,0x1c)
52253 ghc-stage2 GIO fd 2 wrote 28 bytes
"ghc-stage2: internal error: "
```
## Expected behavior
Working ghci.
## Environment
* GHC version used: 9.3 snapshot
Optional:
* Operating System: OpenBSD 7.0-current
* System Architecture: amd64Ben GamariBen Gamarihttps://gitlab.haskell.org/ghc/ghc/-/issues/20869Ignore linker script loading on OpenBSD2022-01-07T11:08:40ZGreg SteuckIgnore linker script loading on OpenBSDStarting with e020e387b3da272ef9750bad5f585119cbaf387 which addressed #2615 ghci had support for loading linker scripts as `.so`. This capability is verified with `T2615.hs` test. The test fails on OpenBSD because the regexp looking for ...Starting with e020e387b3da272ef9750bad5f585119cbaf387 which addressed #2615 ghci had support for loading linker scripts as `.so`. This capability is verified with `T2615.hs` test. The test fails on OpenBSD because the regexp looking for this condition is not sufficient to match the error message returned by OpenBSD `ld.so`. The small attached program (extracted out of Linker.c)[l.c](/uploads/277842b74cfba58ec25653bef97b3fd7/l.c) demonstrates the condition and its output is:
```
errmsg = 'File not an ELF object'
result = 1
result File not an ELF object
```
The `re_invalid` could conceivably be expanded to match this error as well, but the underlying assumption that the file name is included into `dlerror` result does NOT hold on OpenBSD.
Luckily, OpenBSD doesn't ship any system libraries fronted by linker scripts. Hence the only impact at the moment is the broken test which I'll mark to be ignored.https://gitlab.haskell.org/ghc/ghc/-/issues/202799.2.1-rc1 fails to compile on OpenBSD2021-09-10T22:27:29Zkgardas9.2.1-rc1 fails to compile on OpenBSDThe compilation failure in in libraries/base where configure.ac is not able to detect provided libiconv iconv.h file. The patch with explanation is already on a master:
commit 31dc013fdec0cf2ddac1ba093c8a6933a0b62df2
Author: Greg Steuck...The compilation failure in in libraries/base where configure.ac is not able to detect provided libiconv iconv.h file. The patch with explanation is already on a master:
commit 31dc013fdec0cf2ddac1ba093c8a6933a0b62df2
Author: Greg Steuck <greg@nest.cx>
Date: Sun Jun 6 22:30:52 2021 -0700
Fix iconv detection in configure on OpenBSD
This regressed in 544414ba604b13e0992ad87e90b8bdf45c43011c causing
configure: error: iconv is required on non-Windows platforms
More details:
https://gitlab.haskell.org/ghc/ghc/-/commit/544414ba604b13e0992ad87e90b8bdf45c43011c#3bae3b74ae866493bd6b79df16cb638a5f2e0f87_106_106
Would be great if this may be cherry picked to 9.2 branch too.9.2.1Ben GamariBen Gamari