ldc
ldc copied to clipboard
help to port ldc to Debian riscv64
Hi, I am porting the ldc package to Debian riscv64 arch. The original patch is here I refer to here: https://github.com/felixonmars/archriscv-packages/blob/master/ldc/riscv64.patch
Now it seems that everything is ok, but I am stuck in here:
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): OFF
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): OFF
-- -- Building LDC with enabled assertions (LDC_ENABLE_ASSERTIONS): OFF
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
CMake Error at cmake/Modules/ExtractDMDSystemLinker.cmake:42 (message):
Failed to link empty D program using
'/<<PKGBUILDDIR>>/bootstrap-stage2/bin/ldmd2 -wi':
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `no symbol':
dmain2.d:(.text.rt_init+0x20): undefined reference to
`__atomic_fetch_add_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `.LBB1_13':
dmain2.d:(.text.rt_init+0xb8): undefined reference to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `no symbol':
dmain2.d:(.text.rt_term+0x18): undefined reference to `__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `.LBB3_16':
dmain2.d:(.text.rt_term+0x38): undefined reference to
`__atomic_fetch_sub_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(lifetime.o):
in function `.LBB13_29':
lifetime.d:(.text._D2rt8lifetime21__setArrayAllocLengthFNaNbKS4core6memory8BlkInfo_mbxC8TypeInfomZb+0x90):
undefined reference to `__atomic_compare_exchange_1'
/usr/bin/ld:
lifetime.d:(.text._D2rt8lifetime21__setArrayAllocLengthFNaNbKS4core6memory8BlkInfo_mbxC8TypeInfomZb+0x104):
undefined reference to `__atomic_compare_exchange_2'
/usr/bin/ld:
lifetime.d:(.text._D2rt8lifetime21__setArrayAllocLengthFNaNbKS4core6memory8BlkInfo_mbxC8TypeInfomZb+0x140):
undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `no symbol':
monitor_.d:(.text._D2rt8monitor_13ensureMonitorFNbC6ObjectZPOSQBqQBq7Monitor+0x28):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `.LBB1_13':
monitor_.d:(.text._D2rt8monitor_13ensureMonitorFNbC6ObjectZPOSQBqQBq7Monitor+0x8c):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `.LBB1_14':
monitor_.d:(.text._D2rt8monitor_13ensureMonitorFNbC6ObjectZPOSQBqQBq7Monitor+0xd8):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
monitor_.d:(.text._D2rt8monitor_13ensureMonitorFNbC6ObjectZPOSQBqQBq7Monitor+0xfc):
undefined reference to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `no symbol':
monitor_.d:(.text._d_monitordelete+0x2c): undefined reference to
`__atomic_load_8'
/usr/bin/ld: monitor_.d:(.text._d_monitordelete+0x54): undefined reference
to `__atomic_fetch_sub_8'
/usr/bin/ld: monitor_.d:(.text._d_monitordelete+0xd8): undefined reference
to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `_D2rt8monitor_10getMonitorFNaNbNiC6ObjectZPOSQBrQBr7Monitor':
monitor_.d:(.text._D2rt8monitor_10getMonitorFNaNbNiC6ObjectZPOSQBrQBr7Monitor+0x10):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(monitor_.o):
in function `no symbol':
monitor_.d:(.text._d_monitordelete_nogc+0x20): undefined reference to
`__atomic_load_8'
/usr/bin/ld: monitor_.d:(.text._d_monitordelete_nogc+0x48): undefined
reference to `__atomic_fetch_sub_8'
/usr/bin/ld: monitor_.d:(.text._d_monitordelete_nogc+0x80): undefined
reference to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(spinlock.o):
in function `no symbol':
spinlock.d:(.text._D4core8internal8spinlock8SpinLock4lockMOFNbNiNeZv+0x38):
undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld:
spinlock.d:(.text._D4core8internal8spinlock8SpinLock4lockMOFNbNiNeZv+0x90):
undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld:
spinlock.d:(.text._D4core8internal8spinlock8SpinLock4lockMOFNbNiNeZv+0xa4):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
spinlock.d:(.text._D4core8internal8spinlock8SpinLock4lockMOFNbNiNeZv+0xd8):
undefined reference to `__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(spinlock.o):
in function `_D4core8internal8spinlock8SpinLock6unlockMOFNbNiNeZv':
spinlock.d:(.text._D4core8internal8spinlock8SpinLock6unlockMOFNbNiNeZv+0x10):
undefined reference to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(osthread.o):
in function `no symbol':
osthread.d:(.text._D4core6thread8osthread6Thread9isRunningMFNbNdNiZb+0x2c):
undefined reference to `__atomic_load_1'
/usr/bin/ld:
osthread.d:(.text._D4core6thread8osthread12attachThreadFNbNiCQBpQBn10threadbase10ThreadBaseZQBg+0xb0):
undefined reference to `__atomic_store_1'
/usr/bin/ld:
osthread.d:(.text._D4core6thread8osthread7suspendFNbNiCQBjQBhQBd6ThreadZb+0x98):
undefined reference to `__atomic_load_1'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(osthread.o):
in function `.LBB31_21':
osthread.d:(.text._D4core6thread8osthread7suspendFNbNiCQBjQBhQBd6ThreadZb+0x1a4):
undefined reference to `__atomic_load_1'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(osthread.o):
in function `.LBB33_9':
osthread.d:(.text._D4core6thread8osthread6resumeFNbNiCQBiQBg10threadbase10ThreadBaseZv+0x70):
undefined reference to `__atomic_load_1'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(critical_.o):
in function `no symbol':
critical_.d:(.text._d_criticalenter2+0x18): undefined reference to
`__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(critical_.o):
in function `.LBB4_5':
critical_.d:(.text._d_criticalenter2+0x5c): undefined reference to
`__atomic_load_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(critical_.o):
in function `.LBB4_6':
critical_.d:(.text._d_criticalenter2+0xac): undefined reference to
`__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(gc.o):
in function `no symbol':
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx15stopScanThreadsMFNbZv+0x64):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx15stopScanThreadsMFNbZv+0xac):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(gc.o):
in function `.LBB194_27':
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx12markParallelMFNbbZv+0x2f4):
undefined reference to `__atomic_fetch_add_4'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(gc.o):
in function `.LBB194_28':
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx12markParallelMFNbbZv+0x374):
undefined reference to `__atomic_fetch_sub_4'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(gc.o):
in function `.LBB210_6':
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx14scanBackgroundMFNbZv+0x94):
undefined reference to `__atomic_fetch_add_4'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(gc.o):
in function `no symbol':
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi1ZQBcMFNbNiZv+0x2c):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi1ZQBcMFNbNiZv+0x58):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi1ZQBcMFNbNiZv+0x2ac):
undefined reference to `__atomic_fetch_sub_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi1ZQBcMFNbNiZv+0x2bc):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi1ZQBcMFNbNiZv+0x2e0):
undefined reference to `__atomic_fetch_add_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi0ZQBcMFNbNiZv+0x30):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi0ZQBcMFNbNiZv+0x48):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi0ZQBcMFNbNiZv+0x154):
undefined reference to `__atomic_fetch_sub_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi0ZQBcMFNbNiZv+0x164):
undefined reference to `__atomic_load_4'
/usr/bin/ld:
gc.d:(.text._D4core8internal2gc4impl12conservativeQw3Gcx__T21pullFromScanStackImplVbi0ZQBcMFNbNiZv+0x188):
undefined reference to `__atomic_fetch_add_4'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(fiber.o):
in function `no symbol':
fiber.d:(.text.fiber_entryPoint+0x38): undefined reference to
`__atomic_store_1'
/usr/bin/ld:
fiber.d:(.text._D4core6thread5fiber5Fiber9switchOutMFNbNiZv+0x48):
undefined reference to `__atomic_store_1'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(fiber.o):
in function `.LBB3_1':
fiber.d:(.text._D4core6thread5fiber5Fiber9switchOutMFNbNiZv+0x90):
undefined reference to `__atomic_store_1'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(bits.o):
in function `_D4core8internal2gc4bits6GCBits9setLockedMFNbNimZm':
bits.d:(.text._D4core8internal2gc4bits6GCBits9setLockedMFNbNimZm+0x2c):
undefined reference to `__atomic_fetch_or_8'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1
Call Stack (most recent call first):
CMakeLists.txt:679 (include)
The background is that linking with -pthread automatically links with libatomic, however glibc 2.34 made the -pthread flag not fully necessary anymore, and cmake decided to stop using it. The workaround is to explicitly link with libatomic. I have tried to link libatomic explicity in CMakeLists, but it does not work. So could you have a look to how to link libatomic here? thanks
AFAICT the problem is that the bootstrap D compiler does not link in libatomic. This can be fixed by adding it to the bootstrap compiler config file (which is generated by CMake). Not sure, but try adding it here: https://github.com/felixonmars/archriscv-packages/blob/79bce0bdd4ce292e75b25f86b5c0380615e4eea6/ldc/riscv64.patch#L48 Something like this perhaps:
- -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-link-defaultlib-shared\""
+ -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-link-defaultlib-shared, -latomic\""
I am porting the ldc package to Debian riscv64 arch.
Cool, thx! - Should be easier with the next LDC version, where the open PRs will be merged.
LDC has -platformlib
for these C lib deps. On Linux, it defaults to -platformlib=rt,dl,pthread,m
, so I'd suggest adding it there, and doing so via CMake -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-platformlib=…\""
makes sure it ends up in the ldc2.conf
file. You'll need that for the bootstrap compiler and the final one. You might also need to set C_SYSTEM_LIBS accordingly for the shared libs.
Hi, @JohanEngelen and @kinke many thanks for helping me to fix the issue. I'm very ashamed that with such detailed guidance from you, I still haven't solved this problem.:(
Basic logic is below:
+--- a/runtime/CMakeLists.txt
++++ b/runtime/CMakeLists.txt
+@@ -123,6 +123,9 @@
+ set(C_SYSTEM_LIBS m c)
+ elseif("${TARGET_SYSTEM}" MATCHES "Linux")
+ set(C_SYSTEM_LIBS m pthread rt dl z)
++ if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
++ set(C_SYSTEM_LIBS atomic)
++ endif()
+ else()
+ set(C_SYSTEM_LIBS m pthread z)
+ endif()
+@@ -348,8 +351,8 @@
+ )
+ endfunction()
+
+- set(target_arch "AArch64;AMDGPU;ARM;Mips;NVPTX;PowerPC;SystemZ;X86")
+- set(target_name "aarch64;amdgcn;arm;mips;nvvm;ppc;s390;x86")
++ set(target_arch "AArch64;AMDGPU;ARM;Mips;NVPTX;PowerPC;RISCV;SystemZ;X86")
++ set(target_name "aarch64;amdgcn;arm;mips;nvvm;ppc;riscv64;s390;x86")
+
+ foreach(target ${LLVM_TARGETS_TO_BUILD})
+ list(FIND target_arch ${target} idx)
+@@ -599,7 +602,7 @@
+ ${druntime_o} ${DRUNTIME_C} ${DRUNTIME_ASM})
+ set_common_library_properties(druntime-ldc${target_suffix}
+ druntime-ldc${lib_suffix} ${output_path}
+- "${c_flags}" "${ld_flags} -lz" ${is_shared}
++ "${c_flags}" "${ld_flags} -lz -latomic" ${is_shared}
+ )
+
+ # When building a shared library, we need to link in all the default
+@@ -616,7 +619,7 @@
+ ${phobos2_o} ${PHOBOS2_C})
+ set_common_library_properties(phobos2-ldc${target_suffix}
+ phobos2-ldc${lib_suffix} ${output_path}
+- "${c_flags}" "${ld_flags} -lz" ${is_shared}
++ "${c_flags}" "${ld_flags} -lz -latomic" ${is_shared}
+ )
+
+ if("${is_shared}" STREQUAL "ON")
+--- a/cmake/Modules/BuildDExecutable.cmake
++++ b/cmake/Modules/BuildDExecutable.cmake
+@@ -74,7 +74,7 @@
+ RUNTIME_OUTPUT_DIRECTORY ${output_dir}
+ LINKER_LANGUAGE CXX
+ )
+- target_link_libraries(${target_name} ${link_deps} ${linker_args} ${D_LINKER_ARGS} "-lz")
++ target_link_libraries(${target_name} ${link_deps} ${linker_args} ${D_LINKER_ARGS} "-lz -latomic")
+ else()
+ # Use a response file on Windows when compiling separately, in order not to
+ # exceed the max command-line length.
diff -Nru ldc-1.30.0/debian/rules ldc-1.30.0/debian/rules
--- ldc-1.30.0/debian/rules 2022-08-12 16:36:13.000000000 +0000
+++ ldc-1.30.0/debian/rules 2022-08-12 18:28:55.000000000 +0000
@@ -8,7 +8,7 @@
CXXFLAGS += $(CPPFLAGS)
LDC_BUILD_FLAGS = -DINCLUDE_INSTALL_DIR='/usr/lib/ldc/${DEB_HOST_MULTIARCH}/include/d' \
- -DLDC_DYNAMIC_COMPILE=OFF
+ -DLDC_DYNAMIC_COMPILE=OFF -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-platformlib=rt,dl,pthread,m,atomic\""
BOOTSTRAP_LDC_FLAGS = -DD_COMPILER=/usr/bin/gdmd -DBUILD_SHARED_LIBS=ON
I think there is no value to add -latomic in set_common_library_properties, but in practice, but this doesn't help to link atomic. Add I have to set "-DLDC_DYNAMIC_COMPILE" flag in debian/rule, is it right?
The fail log is here:
-- No package 'LLVMSPIRVLib' found
-- -- Building LDC without SPIR-V support: not found
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- LDC version identifier: 1.30.0
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): OFF
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): OFF
-- -- Building LDC with enabled assertions (LDC_ENABLE_ASSERTIONS): OFF
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
CMake Error at cmake/Modules/ExtractDMDSystemLinker.cmake:42 (message):
Failed to link empty D program using
'/<<PKGBUILDDIR>>/bootstrap-stage2/bin/ldmd2 -wi':
/usr/bin/ld: cannot find -latomic-link-defaultlib-shared=false: No such
file or directory
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1
Call Stack (most recent call first):
CMakeLists.txt:671 (include)
-- Configuring incomplete, errors occurred!
It seems it was stuck on stage2. Thanks again~
Hmm, I'd think adding -DC_SYSTEM_LIBS='atomic;m;pthread;rt;dl;z' -DADDITIONAL_DEFAULT_LDC_SWITCHES='"-platformlib=atomic,rt,dl,pthread,m"'
for all stages (incl. BOOTSTRAP_LDC_FLAGS
) should be sufficient - no need to mod set_common_library_properties
calls and BuildDExecutable.cmake
. [In the snippet above, you overwrite C_SYSTEM_LIBS
to atomic
only, that probably won't work.]
The error above is probably caused by a wrong ldc2.conf
for the bootstrap compiler - I suggest checking …/bootstrap-stage2/{bin,etc}/ldc2.conf
.
Now the progress is:
diff -upN tmp/ldc-1.30.0/debian/rules ldc-1.30.0/debian/rules
--- tmp/ldc-1.30.0/debian/rules 2022-08-12 16:36:13.000000000 +0000
+++ ldc-1.30.0/debian/rules 2022-09-19 09:13:51.666894206 +0000
@@ -7,9 +7,18 @@ include /usr/share/dpkg/architecture.mk
CFLAGS += $(CPPFLAGS)
CXXFLAGS += $(CPPFLAGS)
+# Link with libatomic on riscv64 to get access to the __atomic_*_1 functions
+ifeq ($(DEB_HOST_ARCH),riscv64)
+ export DEB_LDFLAGS_MAINT_APPEND += -Wl,--no-as-needed -latomic -Wl,--as-needed
+endif
+
LDC_BUILD_FLAGS = -DINCLUDE_INSTALL_DIR='/usr/lib/ldc/${DEB_HOST_MULTIARCH}/include/d' \
- -DLDC_DYNAMIC_COMPILE=OFF
-BOOTSTRAP_LDC_FLAGS = -DD_COMPILER=/usr/bin/gdmd -DBUILD_SHARED_LIBS=ON
+ -DLDC_DYNAMIC_COMPILE=OFF -DC_SYSTEM_LIBS='atomic;m;pthread;rt;dl;z'
+ -DADDITIONAL_DEFAULT_LDC_SWITCHES='"-platformlib=atomic,rt,dl,pthread,m"'
+
+BOOTSTRAP_LDC_FLAGS = -DD_COMPILER=/usr/bin/gdmd -DBUILD_SHARED_LIBS=ON
+ -DLDC_DYNAMIC_COMPILE=OFF -DC_SYSTEM_LIBS='atomic;m;pthread;rt;dl;z'
+ -DADDITIONAL_DEFAULT_LDC_SWITCHES='"-platformlib=atomic,rt,dl,pthread,m"'
ifeq ($(DEB_HOST_ARCH),armhf)
LDC_BUILD_FLAGS += -DD_COMPILER_FLAGS=-mattr=-neon
The result is still stuck in:
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): OFF
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): OFF
-- -- Building LDC with enabled assertions (LDC_ENABLE_ASSERTIONS): OFF
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
CMake Error at cmake/Modules/ExtractDMDSystemLinker.cmake:42 (message):
Failed to link empty D program using
'/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/bin/ldmd2 -wi':
/usr/bin/ld:
/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `no symbol':
dmain2.d:(.text.rt_init+0x20): undefined reference to
`__atomic_fetch_add_8'
/usr/bin/ld:
/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `.LBB1_13':
dmain2.d:(.text.rt_init+0xb8): undefined reference to `__atomic_store_8'
...
cat bootstrap-stage2/bin/ldc2.conf
// See comments in driver/config.d in ldc source tree for grammar description of
// this config file.
// For cross-compilation, you can add sections for specific target triples by
// naming the sections as (quoted) regex patterns. See LDC's `-v` output
// (`config` line) to figure out your normalized triple, depending on the used
// `-mtriple`, `-m32` etc. E.g.:
//
// "^arm.*-linux-gnueabihf$": { … };
// "86(_64)?-.*-linux": { … };
// "i[3-6]86-.*-windows-msvc": { … };
//
// Later sections take precedence and override settings from previous matching
// sections while inheriting unspecified settings from previous sections.
// A `default` section always matches (treated as ".*") and is therefore usually
// the first section.
default:
{
// default switches injected before all explicit command-line switches
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
// default switches appended after all explicit command-line switches
post-switches = [
"-I/home/vimer/build/08/40_ldc/ldc-1.30.0/runtime/druntime/src",
"-I/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/runtime/import",
"-I/home/vimer/build/08/40_ldc/ldc-1.30.0/runtime/jit-rt/d",
"-I/home/vimer/build/08/40_ldc/ldc-1.30.0/runtime/phobos",
];
// default directories to be searched for libraries when linking
lib-dirs = [
"/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/lib",
];
// default rpath when linking against the shared default libs
rpath = "/home/vimer/build/08/40_ldc/ldc-1.30.0/bootstrap-stage2/lib";
};
"^wasm(32|64)-":
{
switches = [
"-defaultlib=",
"-L-z", "-Lstack-size=1048576",
"-L--stack-first",
"-L--export-dynamic",
];
lib-dirs = [];
};
Other than that, I didn't modify other configuration about atomic.
Now I can build debian riscv64 package with yours help. But I have to find a workround:
+ if(NOT "${result_code}" STREQUAL "0")
+- message(FATAL_ERROR "Failed to link empty D program using '${D_COMPILER} ${D_COMPILER_FLAGS} ${DFLAGS_BASE}':\n${stderr}")
++ elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
++ message("on riscv64 arch, not check the cmake result_code")
++ else()
++ message(FATAL_ERROR "Failed to link empty D program using '${D_COMPILER} ${D_COMPILER_FLAGS} ${DFLAGS_BASE}':\n${stderr}")
+ endif()
If I do not do it, it will report the original error:
Failed to link empty D program using
'/<<PKGBUILDDIR>>/bootstrap-stage2/bin/ldmd2 -wi':
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `no symbol':
dmain2.d:(.text.rt_init+0x20): undefined reference to
`__atomic_fetch_add_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `.LBB1_13':
dmain2.d:(.text.rt_init+0xb8): undefined reference to `__atomic_store_8'
/usr/bin/ld:
/<<PKGBUILDDIR>>/bootstrap-stage2/lib/libdruntime-ldc.a(dmain2.o):
in function `no symbol':
....
I can confirm it the libdruntime-ldc.a
file already has atomic symbols table. But I am not sure why ld can not find them.
I will close the issue in next days.
thanks again~
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1021584
Looks like -DADDITIONAL_DEFAULT_LDC_SWITCHES='"-platformlib=atomic,rt,dl,pthread,m"'
isn't used for building the bootstrap-stage2
compiler then - otherwise they would be present in bootstrap-stage2/bin/ldc2.conf
, appended to switches
of the default
section.