-
-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
help to port ldc to Debian riscv64 #4046
Comments
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: - -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-link-defaultlib-shared\""
+ -DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-link-defaultlib-shared, -latomic\"" |
Cool, thx! - Should be easier with the next LDC version, where the open PRs will be merged. LDC has |
Hi, @JohanEngelen and @kinke 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. The fail log is here:
It seems it was stuck on stage2. |
Hmm, I'd think adding The error above is probably caused by a wrong |
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:
// 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 I do not do it, it will report the original error:
I can confirm it the |
Looks like |
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:
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
The text was updated successfully, but these errors were encountered: