NativeAmd64Asm: ld.lld: error: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment
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)
%