From 05d64da61d761315d0c3d785ff023492ab5d452f Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 15:50:50 +0200 Subject: [PATCH 01/21] Initial set of changes based on the FreeBSD port maintained by Erik Jensen (https://www.freshports.org/devel/root) --- core/dictgen/src/rootcling_impl.cxx | 1 - core/metacling/src/TCling.cxx | 8 ++++---- core/metacling/src/rootclingTCling.cxx | 5 +++++ interpreter/cling/lib/Utils/PlatformPosix.cpp | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index f56ce23b7ac0c..8ea5085120261 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -59,7 +59,6 @@ #include #endif - #include "cling/Interpreter/Interpreter.h" #include "cling/Interpreter/InterpreterCallbacks.h" #include "cling/Interpreter/LookupHelper.h" diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 0629d55e79217..0e229496a0ce4 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -163,7 +163,7 @@ clang/LLVM technology. #include #endif -#ifdef R__LINUX +#if defined(R__LINUX) || defined(R__FBSD) # ifndef _GNU_SOURCE # define _GNU_SOURCE # endif @@ -3264,7 +3264,7 @@ static bool R__UpdateLibFileForLinking(TString &lib) } #endif // R__MACOSX -#ifdef R__LINUX +#if defined (R__LINUX) || defined (R__FBSD) //////////////////////////////////////////////////////////////////////////////// /// Callback for dl_iterate_phdr(), see `man dl_iterate_phdr`. @@ -3290,7 +3290,7 @@ static int callback_for_dl_iterate_phdr(struct dl_phdr_info *info, size_t size, return 0; } -#endif // R__LINUX +#endif // R__LINUX || R__FBSD //////////////////////////////////////////////////////////////////////////////// @@ -3337,7 +3337,7 @@ void TCling::UpdateListOfLoadedSharedLibraries() ++imageIndex; } fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex; -#elif defined(R__LINUX) +#elif defined(R__LINUX) || defined(R__FBSD) // fPrevLoadedDynLibInfo is unused on Linux. (void) fPrevLoadedDynLibInfo; diff --git a/core/metacling/src/rootclingTCling.cxx b/core/metacling/src/rootclingTCling.cxx index e168f25f3592f..5f60418b880f5 100644 --- a/core/metacling/src/rootclingTCling.cxx +++ b/core/metacling/src/rootclingTCling.cxx @@ -20,6 +20,11 @@ #undef R__DLLEXPORT +#ifdef __FreeBSD__ +char* __progname; +char** environ; +#endif + #include "TROOT.h" #include "TCling.h" diff --git a/interpreter/cling/lib/Utils/PlatformPosix.cpp b/interpreter/cling/lib/Utils/PlatformPosix.cpp index a01887d673b38..68da3a67ff9be 100644 --- a/interpreter/cling/lib/Utils/PlatformPosix.cpp +++ b/interpreter/cling/lib/Utils/PlatformPosix.cpp @@ -169,7 +169,7 @@ bool Popen(const std::string& Cmd, llvm::SmallVectorImpl& Buf, bool RdE) { } bool GetSystemLibraryPaths(llvm::SmallVectorImpl& Paths) { -#if defined(__APPLE__) || defined(__CYGWIN__) +#if defined(__APPLE__) || defined(__CYGWIN__) || defined(R__FBSD) Paths.push_back("/usr/local/lib/"); Paths.push_back("/usr/X11R6/lib/"); Paths.push_back("/usr/lib/"); From 34e51bcb9f39ff9e0f8941a91723c32bdd4f93e6 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 14:55:38 +0200 Subject: [PATCH 02/21] Add SetUpFreeBSD.cmake and use it --- cmake/modules/CheckCompiler.cmake | 2 + cmake/modules/SetUpFreeBSD.cmake | 149 ++++++++++++++++++++++++++++++ config/root-config.in | 21 ++++- etc/Makefile.arch | 9 ++ 4 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 cmake/modules/SetUpFreeBSD.cmake diff --git a/cmake/modules/CheckCompiler.cmake b/cmake/modules/CheckCompiler.cmake index a45d721e10d6d..015d74f52566d 100644 --- a/cmake/modules/CheckCompiler.cmake +++ b/cmake/modules/CheckCompiler.cmake @@ -204,6 +204,8 @@ endif() #---Setup details depending on the major platform type---------------------------------------------- if(CMAKE_SYSTEM_NAME MATCHES Linux) include(SetUpLinux) +elseif(CMAKE_SYSTEM_NAME MATCHES FreeBSD) + include(SetUpFreeBSD) elseif(APPLE) include(SetUpMacOS) elseif(WIN32) diff --git a/cmake/modules/SetUpFreeBSD.cmake b/cmake/modules/SetUpFreeBSD.cmake new file mode 100644 index 0000000000000..9ff4c0bd97ce3 --- /dev/null +++ b/cmake/modules/SetUpFreeBSD.cmake @@ -0,0 +1,149 @@ +# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. +# All rights reserved. +# +# For the licensing terms see $ROOTSYS/LICENSE. +# For the list of contributors see $ROOTSYS/README/CREDITS. + +set(ROOT_PLATFORM freebsd) + +if(CMAKE_SYSTEM_PROCESSOR MATCHES x86_64 OR CMAKE_SYSTEM_PROCESSOR MATCHES amd64) + if(CMAKE_CXX_COMPILER_ID STREQUAL Intel) + set(ROOT_ARCHITECTURE freebsdx8664icc) + else() + set(ROOT_ARCHITECTURE freebsdx8664) + endif() +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES i686) + set(FP_MATH_FLAGS "-msse2 -mfpmath=sse") + if(CMAKE_CXX_COMPILER_ID STREQUAL Intel) + set(ROOT_ARCHITECTURE freebsdicc) + else() + set(ROOT_ARCHITECTURE freebsd) + endif() +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES aarch64) + set(ROOT_ARCHITECTURE freebsdarm64) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES arm) + set(ROOT_ARCHITECTURE freebsdarm) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES ppc64 OR + CMAKE_SYSTEM_PROCESSOR MATCHES powerpc64 OR + CMAKE_SYSTEM_PROCESSOR MATCHES powerpc64le) + set(ROOT_ARCHITECTURE freebsdppc64gcc) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390x) + set(ROOT_ARCHITECTURE freebsds390xgcc) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390) + set(ROOT_ARCHITECTURE freebsds390gcc) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES riscv64) + set(ROOT_ARCHITECTURE freebsdriscv64) +else() + message(FATAL_ERROR "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}") +endif() + +# JIT must be able to resolve symbols from all ROOT binaries. +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic") + +# Set developer flags +if(dev) + # Warnings are errors. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + + # Do not relink just because a dependent .so has changed. + # I.e. relink only if a header included by the libs .o-s has changed, + # whether or not that header "belongs" to a different .so. + set(CMAKE_LINK_DEPENDS_NO_SHARED On) + + # Split debug info for faster builds. + if(NOT gnuinstall) + # We won't install DWARF files. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsplit-dwarf") + endif() + + # Try faster lld: + execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET) + if("${stdout}" MATCHES "LLD ") + set(SUPERIOR_LINKER "lld") + endif() + # Only lld supports --gdb-index + if(SUPERIOR_LINKER) + set(LLVM_USE_LINKER "${SUPERIOR_LINKER}") + if(_BUILD_TYPE_UPPER MATCHES "DEB") + message(STATUS "Using ${SUPERIOR_LINKER} linker with gdb-index") + set(GDBINDEX "-Wl,--gdb-index") + else() + message(STATUS "Using ${SUPERIOR_LINKER} linker") + endif() + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") + set(LLVM_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") + set(LLVM_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") + endif() +endif() + +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe ${FP_MATH_FLAGS} -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -W") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -std=legacy") + + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--hash-style=\"both\"") + + if(asan) + # See also core/sanitizer/README.md for what's happening. + execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address) + set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -z undefs") + set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") + endif() + +elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe ${FP_MATH_FLAGS} -Wall -W -Woverloaded-virtual -fsigned-char") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -W") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -std=legacy") + + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") + endif() + + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") + + if(asan) + # See also core/sanitizer/README.md for what's happening. + execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope) + set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs") + set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") + endif() + +elseif(CMAKE_CXX_COMPILER_ID STREQUAL Intel) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd1476") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -restrict") + + # Check icc compiler version and set compile flags according to the + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v + ERROR_VARIABLE _icc_version_info ERROR_STRIP_TRAILING_WHITESPACE) + + string(REGEX REPLACE "(^V|^icc[ ]v|^icpc[ ]v)ersion[ ]([0-9]+)\\.[0-9]+.*" "\\2" ICC_MAJOR "${_icc_version_info}") + string(REGEX REPLACE "(^V|^icc[ ]v|^icpc[ ]v)ersion[ ][0-9]+\\.([0-9]+).*" "\\2" ICC_MINOR "${_icc_version_info}") + + if(ICC_MAJOR GREATER 9 OR ICC_MAJOR EQUAL 9) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd1572") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd1572") + endif() + + if(ICC_MAJOR GREATER 11 OR ICC_MAJOR EQUAL 11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd279") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd279") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") + endif() + + if(ICC_MAJOR GREATER 14 OR ICC_MAJOR EQUAL 14) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd873 -wd2536") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd873 -wd2536") + endif() + + if(ICC_MAJOR GREATER 15 OR ICC_MAJOR EQUAL 15) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd597 -wd1098 -wd1292 -wd1478 -wd3373") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd597 -wd1098 -wd1292 -wd1478 -wd3373") + endif() + + # Augment optimisation flags: + set(CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER} "${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}} -fp-model precise") + set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${_BUILD_TYPE_UPPER}} -fp-model precise") +endif() diff --git a/config/root-config.in b/config/root-config.in index a7756c593d7ad..6b8232882a43f 100755 --- a/config/root-config.in +++ b/config/root-config.in @@ -267,6 +267,11 @@ freebsd) auxcflags="${cxxversionflag}" auxlibs="-lm -lg++" ;; +freebsdx8664) + # FreeBSD with libc5 + auxcflags="${cxxversionflag}" + auxlibs="-lm -lg++" + ;; freebsd4) # FreeBSD 4 with glibc auxcflags="${cxxversionflag}" @@ -368,7 +373,21 @@ esac ### compiler dependent settings ### case $arch in -freebsd* | openbsd* | linux*) +freebsd*) + auxcflags="-pthread -D_REENTRANT $auxcflags" + auxlibs="-pthread $auxlibs" + + for f in $features ; do + if test "x$f" = "xrpath" ; then + auxlibs="-Wl,-rpath,$libdir $auxlibs" + fi + if test "x$f" = "xlibcxx" ; then + auxcflags="-stdlib=libc++ $auxcflags" + auxlibs="-stdlib=libc++ $auxlibs" + fi + done + ;; +openbsd* | linux*) auxcflags="-pthread $auxcflags" auxlibs="-pthread $auxlibs" diff --git a/etc/Makefile.arch b/etc/Makefile.arch index d2eaeaec62783..b00510a63f7fe 100644 --- a/etc/Makefile.arch +++ b/etc/Makefile.arch @@ -286,6 +286,15 @@ LDFLAGS = $(OPT) SOFLAGS = -shared -Wl,-x endif +ifeq ($(ARCH),freebsdx8664) +# FreeBSD with libc +CXX = c++ +CXXFLAGS = $(OPT) -W -Wall -fPIC +LD = $(CXX) +LDFLAGS = $(OPT) +SOFLAGS = -shared -Wl,-x +endif + ifeq ($(ARCH),openbsd) # OpenBSD with libc CXX = g++ From 46adf1d0a42e2b161a86f9c7d20861effa7786a5 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 15:44:03 +0200 Subject: [PATCH 03/21] Don't use gnu extensions in sed --- build/unix/compiledata.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/unix/compiledata.sh b/build/unix/compiledata.sh index 7ebf12343ff73..f0f5946e6dcd9 100755 --- a/build/unix/compiledata.sh +++ b/build/unix/compiledata.sh @@ -58,7 +58,7 @@ CXXFLAGS=`echo $CXXFLAGS | sed 's/-Iinclude //' ` # Remove the flags turning warnings into errors or extending # the number of warnings. -CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-Werror //g' -e 's/-Werror=\S* //g' -e 's/-Wall //g' -e 's/-Wshadow //g' ` +CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-Werror //g' -e 's/-Werror=[^[:space:]]* //g' -e 's/-Wall //g' -e 's/-Wshadow //g' ` # Determine the compiler version BXX="`basename $CXX`" From e8e5b0a715693784d5152e1a1fd688f9c9781c75 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 15:47:52 +0200 Subject: [PATCH 04/21] Fix linking to crypt lib in FreeBSD --- net/auth/CMakeLists.txt | 1 + net/rpdutils/CMakeLists.txt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/net/auth/CMakeLists.txt b/net/auth/CMakeLists.txt index eee65f3736c42..a98e659ec8649 100644 --- a/net/auth/CMakeLists.txt +++ b/net/auth/CMakeLists.txt @@ -33,3 +33,4 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RootAuth ) target_link_libraries(RootAuth PRIVATE rsa $<$:crypt>) +target_link_libraries(RootAuth PRIVATE rsa $<$:crypt>) diff --git a/net/rpdutils/CMakeLists.txt b/net/rpdutils/CMakeLists.txt index b7c2dd421a3c3..ddfcca65e44e0 100644 --- a/net/rpdutils/CMakeLists.txt +++ b/net/rpdutils/CMakeLists.txt @@ -61,3 +61,8 @@ target_include_directories(SrvAuth PRIVATE ${CMAKE_SOURCE_DIR}/net/auth/inc ${CMAKE_SOURCE_DIR}/rpdutils/res ) + +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(SrvAuth PRIVATE crypt) +endif() + From 71345e25157aaea3686b2ac6202af050ff16ba7a Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Fri, 9 Jun 2023 01:43:50 +0200 Subject: [PATCH 05/21] Add the ability to self inspect the exe path on FreeBSD this should work on FreeBSD 9 and up. only tested on 13. --- core/CMakeLists.txt | 4 +++ core/dictgen/src/rootcling_impl.cxx | 21 +++++++++++++ core/foundation/inc/ThreadLocalStorage.h | 3 ++ core/foundation/src/FoundationUtils.cxx | 27 ++++++++++++++++ core/metacling/src/CMakeLists.txt | 5 +++ core/rootcling_stage1/CMakeLists.txt | 3 ++ core/unix/CMakeLists.txt | 4 +++ core/unix/src/TUnixSystem.cxx | 23 ++++++++++++-- .../DynamicLibraryManagerSymbol.cpp | 31 +++++++++++++++++++ 9 files changed, 118 insertions(+), 3 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 7c16cd54063dd..70531cdba35ad 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -81,6 +81,10 @@ target_link_libraries(Core ${ROOT_ATOMIC_LIBS} ) +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(Core PUBLIC util procstat) +endif() + target_include_directories(Core PUBLIC $ ) diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index 8ea5085120261..19d86ca7ce77b 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -54,6 +54,14 @@ #include #endif +#ifdef R__FBSD +#include +#include +#include +#include +#include +#endif // R__FBSD + #if !defined(R__WIN32) #include #include @@ -206,6 +214,19 @@ const char *GetExePath() exepath = buf; } #endif +#if defined R__FBSD || defined __FreeBSD__ + procstat* ps = procstat_open_sysctl(); // + kinfo_proc* kp = kinfo_getproc(getpid()); + + if (kp!=NULL) { + char path_str[PATH_MAX] = ""; + procstat_getpathname(ps, kp, path_str, sizeof(path_str)); + exepath = path_str; + } + + free(kp); + procstat_close(ps); +#endif #ifdef _WIN32 char *buf = new char[MAX_MODULE_NAME32 + 1]; ::GetModuleFileName(NULL, buf, MAX_MODULE_NAME32 + 1); diff --git a/core/foundation/inc/ThreadLocalStorage.h b/core/foundation/inc/ThreadLocalStorage.h index 5e690567e7d9d..4b7e05606bd03 100644 --- a/core/foundation/inc/ThreadLocalStorage.h +++ b/core/foundation/inc/ThreadLocalStorage.h @@ -80,6 +80,9 @@ #if defined(R__WIN32) # define R__HAS_DECLSPEC_THREAD #endif +#if defined(R__FBSD) +# define R__HAS_PTHREAD +#endif #ifdef __cplusplus diff --git a/core/foundation/src/FoundationUtils.cxx b/core/foundation/src/FoundationUtils.cxx index 40e359644d786..69f55956f877b 100644 --- a/core/foundation/src/FoundationUtils.cxx +++ b/core/foundation/src/FoundationUtils.cxx @@ -25,6 +25,7 @@ #include #include + #ifdef _WIN32 #include #include @@ -32,6 +33,15 @@ #include #endif // _WIN32 +#ifdef __FreeBSD__ +#include +#include +#include +#include +#include +#include +#endif // __FreeBSD__ + namespace ROOT { namespace FoundationUtils { std::string GetCurrentDir() @@ -113,6 +123,23 @@ const std::string& GetFallbackRootSys() { }; fallback = parent_path(parent_path(lpFilename)); } +#elif defined __FreeBSD__ + procstat* ps = procstat_open_sysctl(); // + kinfo_proc* kp = kinfo_getproc(getpid()); + + if (kp!=NULL) { + char path_str[PATH_MAX] = ""; + procstat_getpathname(ps, kp, path_str, sizeof(path_str)); + std::string execpath(path_str); + + auto parent_path = [](std::string path) { + return path.substr(0, path.find_last_of("/\\")); + }; + fallback = parent_path(parent_path({path_str})); + } + + free(kp); + procstat_close(ps); #else // FIXME: We should not hardcode this path. We can use a similar to the // windows technique to get the path to the executable. The easiest way diff --git a/core/metacling/src/CMakeLists.txt b/core/metacling/src/CMakeLists.txt index c631acbd81089..c0942f3bb870a 100644 --- a/core/metacling/src/CMakeLists.txt +++ b/core/metacling/src/CMakeLists.txt @@ -195,3 +195,8 @@ if(APPLE) elseif(NOT MSVC) target_link_libraries(Cling PUBLIC -Wl,--unresolved-symbols=ignore-in-object-files) endif() + +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(Cling PUBLIC util procstat) +endif() + diff --git a/core/rootcling_stage1/CMakeLists.txt b/core/rootcling_stage1/CMakeLists.txt index 75f2415e5d301..a934718bf0087 100644 --- a/core/rootcling_stage1/CMakeLists.txt +++ b/core/rootcling_stage1/CMakeLists.txt @@ -35,6 +35,9 @@ target_include_directories(rootcling_stage1 PRIVATE ${CMAKE_SOURCE_DIR}/core/dictgen/res # for rootcling_impl.h ${CMAKE_BINARY_DIR}/ginclude # for RConfigure.h ) +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(rootcling_stage1 util procstat) +endif() set_target_properties(rootcling_stage1 PROPERTIES RUNTIME_OUTPUT_DIRECTORY src) add_dependencies(rootcling_stage1 ClingUtils) diff --git a/core/unix/CMakeLists.txt b/core/unix/CMakeLists.txt index 32ef6ab59fa8d..1585e5dd4de35 100644 --- a/core/unix/CMakeLists.txt +++ b/core/unix/CMakeLists.txt @@ -16,4 +16,8 @@ set_property(TARGET Core APPEND PROPERTY DICT_HEADERS TUnixSystem.h) target_sources(Core PRIVATE src/TUnixSystem.cxx) target_include_directories(Core PRIVATE inc ../clib/res) +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(Core PRIVATE execinfo util) +endif() + ROOT_INSTALL_HEADERS() diff --git a/core/unix/src/TUnixSystem.cxx b/core/unix/src/TUnixSystem.cxx index ec6435359b90e..d339c97b6e69e 100644 --- a/core/unix/src/TUnixSystem.cxx +++ b/core/unix/src/TUnixSystem.cxx @@ -80,6 +80,14 @@ #elif defined(R__FBSD) || defined(R__OBSD) # include # include +# ifdef R__FBSD +# include +# include +# include +# include +# include +# include +# endif #else # include #endif @@ -180,7 +188,7 @@ extern "C" { # endif # define HAVE_DLADDR #endif -#if defined(R__MACOSX) +#if defined(R__MACOSX) || defined(R__FBSD) # define HAVE_BACKTRACE_SYMBOLS_FD # define HAVE_DLADDR #endif @@ -404,7 +412,7 @@ static const char *GetExePath() #if defined(R__MACOSX) exepath = _dyld_get_image_name(0); #elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD) - char buf[kMAXPATHLEN]; // exe path name + char buf[kMAXPATHLEN]=""; // exe path name // get the name from the link in /proc #if defined(R__LINUX) @@ -412,7 +420,16 @@ static const char *GetExePath() #elif defined(R__SOLARIS) int ret = readlink("/proc/self/path/a.out", buf, kMAXPATHLEN); #elif defined(R__FBSD) - int ret = readlink("/proc/curproc/file", buf, kMAXPATHLEN); + procstat* ps = procstat_open_sysctl(); // + kinfo_proc* kp = kinfo_getproc(getpid()); + + int ret{0}; + if (kp!=NULL) { + procstat_getpathname(ps, kp, buf, sizeof(buf)); + } + free(kp); + procstat_close(ps); + exepath = buf; #endif if (ret > 0 && ret < kMAXPATHLEN) { buf[ret] = 0; diff --git a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index dda5897a3cd46..e44231ec12942 100644 --- a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -37,6 +37,26 @@ #include #include +#if defined (__FreeBSD__) +# include +# include +# include +# include + +// so this is a hack to avoid libprocstat clobbering the elf includes. +// No idea if this will keep working +# ifndef ZFS +# define ZFS +# define thisisabloodyhackZFS +# endif +# include +# ifdef thisisabloodyhackZFS +# undef ZFS +# endif +#undef thisisabloodyhackZFS + +# include +#endif #ifdef LLVM_ON_UNIX #include @@ -1363,6 +1383,17 @@ namespace cling { if (_NSGetExecutablePath(buf, &bufsize) >= 0) return cached_realpath(buf); return cached_realpath(info.dli_fname); +# elif defined (__FreeBSD__) + procstat* ps = procstat_open_sysctl(); // + kinfo_proc* kp = kinfo_getproc(getpid()); + + char buf[PATH_MAX] = ""; + if (kp!=NULL) { + procstat_getpathname(ps, kp, buf, sizeof(buf)); + }; + free(kp); + procstat_close(ps); + return cached_realpath(buf); # elif defined(LLVM_ON_UNIX) char buf[PATH_MAX] = { 0 }; // Cross our fingers that /proc/self/exe exists. From aa14c60f40358d66adffab784a5bb409a01836dc Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Wed, 17 May 2023 19:16:55 +0000 Subject: [PATCH 06/21] Add a poor man's FreeBSD xattr handling, hoping the hardcoded default namespace will do --- io/io/src/TFile.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 63bab928f2d02..fd230f5c3f045 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -85,7 +85,9 @@ The structure of a directory is shown in TDirectoryFile::TDirectoryFile #include #ifndef WIN32 #include +#ifndef R__FBSD #include +#endif #else # define ssize_t int # include @@ -141,6 +143,10 @@ The structure of a directory is shown in TDirectoryFile::TDirectoryFile #include "ROOT/RConcurrentHashColl.hxx" #include +#ifdef R__FBSD +#include +#endif + using std::sqrt; std::atomic TFile::fgBytesRead{0}; @@ -163,6 +169,9 @@ ROOT::Internal::RConcurrentHashColl TFile::fgTsSIHashes; /* On macOS getxattr takes two extra arguments that should be set to 0 */ #define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0) #endif +#ifdef R__FBSD +#define getxattr(path,name,value,size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size) +#endif const Int_t kBEGIN = 100; From 203130c66dab8aaf21bd9d6cb1d373164a8af379 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Fri, 9 Jun 2023 00:48:43 +0200 Subject: [PATCH 07/21] skip trying to load [vdso] as it has no proper path on FreeBSD --- core/metacling/src/TCling.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 0e229496a0ce4..cefcd94345afd 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -3279,6 +3279,9 @@ static int callback_for_dl_iterate_phdr(struct dl_phdr_info *info, size_t size, if (!sKnownLoadedLibBaseAddrs.count(info->dlpi_addr)) { // Skip \0, "", and kernel pseudo-libs linux-vdso.so.1 or linux-gate.so.1 if (info->dlpi_name && info->dlpi_name[0] +#if defined(R__FBSD) + && strstr(info->dlpi_name, "[vdso]") +#endif && strncmp(info->dlpi_name, "linux-vdso.so", 13) && strncmp(info->dlpi_name, "linux-vdso32.so", 15) && strncmp(info->dlpi_name, "linux-vdso64.so", 15) From 54c732d8682474d692e4efaece4d00e6b0a0da33 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 18:03:40 +0200 Subject: [PATCH 08/21] Reword defs Co-authored-by: Axel Naumann --- .../lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index e44231ec12942..7efbc18b46bcd 100644 --- a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -47,15 +47,15 @@ // No idea if this will keep working # ifndef ZFS # define ZFS -# define thisisabloodyhackZFS +# define defined_ZFS_for_libprocstat # endif -# include -# ifdef thisisabloodyhackZFS +# include +# ifdef defined_ZFS_for_libprocstat # undef ZFS +# undef defined_ZFS_for_libprocstat # endif -#undef thisisabloodyhackZFS -# include +# include #endif #ifdef LLVM_ON_UNIX From 96d1820ee24d6813fcc2ad09f7cda7e3f4333e02 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 18:28:18 +0200 Subject: [PATCH 09/21] Update comment on a workaround for elf.h include in libprostat (FreeBSD) --- .../DynamicLibraryManagerSymbol.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 7efbc18b46bcd..291a6df48e148 100644 --- a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -38,25 +38,25 @@ #include #if defined (__FreeBSD__) -# include -# include -# include -# include +#include +#include +#include +#include -// so this is a hack to avoid libprocstat clobbering the elf includes. -// No idea if this will keep working +// libprocstat pulls in sys/elf.h which seems to clash with llvm/BinaryFormat/ELF.h +// similar collision happens with ZFS. Defining ZFS disables this include. # ifndef ZFS # define ZFS # define defined_ZFS_for_libprocstat # endif -# include +#include # ifdef defined_ZFS_for_libprocstat # undef ZFS # undef defined_ZFS_for_libprocstat # endif -# include -#endif +#include +# endif #ifdef LLVM_ON_UNIX #include From af96b2c34ad363084ac143adf6cd1dec8cf10865 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Mon, 12 Jun 2023 18:03:04 +0200 Subject: [PATCH 10/21] Formatting --- core/CMakeLists.txt | 2 +- core/dictgen/src/rootcling_impl.cxx | 1 + core/metacling/src/CMakeLists.txt | 2 +- core/unix/CMakeLists.txt | 2 +- net/rpdutils/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 70531cdba35ad..627b09346fbd5 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -82,7 +82,7 @@ target_link_libraries(Core ) if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) - target_link_libraries(Core PUBLIC util procstat) + target_link_libraries(Core PUBLIC util procstat) endif() target_include_directories(Core PUBLIC diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index 19d86ca7ce77b..b52aa57ea9e94 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -67,6 +67,7 @@ #include #endif + #include "cling/Interpreter/Interpreter.h" #include "cling/Interpreter/InterpreterCallbacks.h" #include "cling/Interpreter/LookupHelper.h" diff --git a/core/metacling/src/CMakeLists.txt b/core/metacling/src/CMakeLists.txt index c0942f3bb870a..d94d013063cac 100644 --- a/core/metacling/src/CMakeLists.txt +++ b/core/metacling/src/CMakeLists.txt @@ -197,6 +197,6 @@ elseif(NOT MSVC) endif() if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) - target_link_libraries(Cling PUBLIC util procstat) + target_link_libraries(Cling PUBLIC util procstat) endif() diff --git a/core/unix/CMakeLists.txt b/core/unix/CMakeLists.txt index 1585e5dd4de35..f1bfed48174af 100644 --- a/core/unix/CMakeLists.txt +++ b/core/unix/CMakeLists.txt @@ -17,7 +17,7 @@ target_sources(Core PRIVATE src/TUnixSystem.cxx) target_include_directories(Core PRIVATE inc ../clib/res) if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) - target_link_libraries(Core PRIVATE execinfo util) + target_link_libraries(Core PRIVATE execinfo util) endif() ROOT_INSTALL_HEADERS() diff --git a/net/rpdutils/CMakeLists.txt b/net/rpdutils/CMakeLists.txt index ddfcca65e44e0..a45c58d5eb52f 100644 --- a/net/rpdutils/CMakeLists.txt +++ b/net/rpdutils/CMakeLists.txt @@ -63,6 +63,6 @@ target_include_directories(SrvAuth PRIVATE ) if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) - target_link_libraries(SrvAuth PRIVATE crypt) + target_link_libraries(SrvAuth PRIVATE crypt) endif() From 65fb8d0c95d1c3f5bddc0d9ccda4450865ae9da3 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Tue, 13 Jun 2023 12:54:11 +0200 Subject: [PATCH 11/21] [FreeBSD] Fix ncpu reporting in root-config --- config/root-config.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/root-config.in b/config/root-config.in index 6b8232882a43f..cf08495b75a3e 100755 --- a/config/root-config.in +++ b/config/root-config.in @@ -803,9 +803,12 @@ while test $# -gt 0; do ### number of available cores ncpu=1 case $arch in - freebsd* | openbsd* | linux*) + openbsd* | linux*) ncpu=$(awk '/^processor/ {++n} END {print n}' /proc/cpuinfo) ;; + freebsd*) + ncpu=$(sysctl -n hw.ncpu) + ;; macosx*) ncpu=$(sysctl -n hw.ncpu) ;; From 9810d449ce420401dfe47117cd0798be202bda81 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Tue, 13 Jun 2023 15:27:46 +0200 Subject: [PATCH 12/21] Clean up SetupFreeBSD.cmake and define freebsdamd64 --- cmake/modules/SetUpFreeBSD.cmake | 82 ++++++-------------------------- config/root-config.in | 4 +- etc/Makefile.arch | 6 +-- 3 files changed, 21 insertions(+), 71 deletions(-) diff --git a/cmake/modules/SetUpFreeBSD.cmake b/cmake/modules/SetUpFreeBSD.cmake index 9ff4c0bd97ce3..c4cfa3e9fe1b3 100644 --- a/cmake/modules/SetUpFreeBSD.cmake +++ b/cmake/modules/SetUpFreeBSD.cmake @@ -7,18 +7,10 @@ set(ROOT_PLATFORM freebsd) if(CMAKE_SYSTEM_PROCESSOR MATCHES x86_64 OR CMAKE_SYSTEM_PROCESSOR MATCHES amd64) - if(CMAKE_CXX_COMPILER_ID STREQUAL Intel) - set(ROOT_ARCHITECTURE freebsdx8664icc) - else() - set(ROOT_ARCHITECTURE freebsdx8664) - endif() + set(ROOT_ARCHITECTURE freebsdamd64) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES i686) set(FP_MATH_FLAGS "-msse2 -mfpmath=sse") - if(CMAKE_CXX_COMPILER_ID STREQUAL Intel) - set(ROOT_ARCHITECTURE freebsdicc) - else() - set(ROOT_ARCHITECTURE freebsd) - endif() + set(ROOT_ARCHITECTURE freebsdi686) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES aarch64) set(ROOT_ARCHITECTURE freebsdarm64) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES arm) @@ -26,11 +18,11 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES arm) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES ppc64 OR CMAKE_SYSTEM_PROCESSOR MATCHES powerpc64 OR CMAKE_SYSTEM_PROCESSOR MATCHES powerpc64le) - set(ROOT_ARCHITECTURE freebsdppc64gcc) + set(ROOT_ARCHITECTURE freebsdppc64) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390x) - set(ROOT_ARCHITECTURE freebsds390xgcc) + set(ROOT_ARCHITECTURE freebsds390x) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390) - set(ROOT_ARCHITECTURE freebsds390gcc) + set(ROOT_ARCHITECTURE freebsds390) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES riscv64) set(ROOT_ARCHITECTURE freebsdriscv64) else() @@ -56,25 +48,17 @@ if(dev) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsplit-dwarf") endif() - # Try faster lld: - execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET) - if("${stdout}" MATCHES "LLD ") - set(SUPERIOR_LINKER "lld") - endif() - # Only lld supports --gdb-index - if(SUPERIOR_LINKER) - set(LLVM_USE_LINKER "${SUPERIOR_LINKER}") - if(_BUILD_TYPE_UPPER MATCHES "DEB") - message(STATUS "Using ${SUPERIOR_LINKER} linker with gdb-index") - set(GDBINDEX "-Wl,--gdb-index") - else() - message(STATUS "Using ${SUPERIOR_LINKER} linker") - endif() - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") - set(LLVM_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") - set(LLVM_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${SUPERIOR_LINKER} ${GDBINDEX}") + if(_BUILD_TYPE_UPPER MATCHES "DEB") + message(STATUS "Using ld.lld linker with gdb-index") + set(GDBINDEX "-Wl,--gdb-index") + else() + message(STATUS "Using ld.lld linker without gdb-index") endif() + + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GDBINDEX}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GDBINDEX}") + set(LLVM_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GDBINDEX}") + set(LLVM_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GDBINDEX}") endif() if(CMAKE_COMPILER_IS_GNUCXX) @@ -110,40 +94,4 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") endif() - -elseif(CMAKE_CXX_COMPILER_ID STREQUAL Intel) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd1476") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -restrict") - - # Check icc compiler version and set compile flags according to the - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v - ERROR_VARIABLE _icc_version_info ERROR_STRIP_TRAILING_WHITESPACE) - - string(REGEX REPLACE "(^V|^icc[ ]v|^icpc[ ]v)ersion[ ]([0-9]+)\\.[0-9]+.*" "\\2" ICC_MAJOR "${_icc_version_info}") - string(REGEX REPLACE "(^V|^icc[ ]v|^icpc[ ]v)ersion[ ][0-9]+\\.([0-9]+).*" "\\2" ICC_MINOR "${_icc_version_info}") - - if(ICC_MAJOR GREATER 9 OR ICC_MAJOR EQUAL 9) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd1572") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd1572") - endif() - - if(ICC_MAJOR GREATER 11 OR ICC_MAJOR EQUAL 11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd279") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd279") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") - endif() - - if(ICC_MAJOR GREATER 14 OR ICC_MAJOR EQUAL 14) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd873 -wd2536") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd873 -wd2536") - endif() - - if(ICC_MAJOR GREATER 15 OR ICC_MAJOR EQUAL 15) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd597 -wd1098 -wd1292 -wd1478 -wd3373") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd597 -wd1098 -wd1292 -wd1478 -wd3373") - endif() - - # Augment optimisation flags: - set(CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER} "${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}} -fp-model precise") - set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${_BUILD_TYPE_UPPER}} -fp-model precise") endif() diff --git a/config/root-config.in b/config/root-config.in index cf08495b75a3e..41cf84ca69cc7 100755 --- a/config/root-config.in +++ b/config/root-config.in @@ -279,8 +279,10 @@ freebsd4) ;; freebsd5|freebsd7) # FreeBSD 5/7 with glibc +freebsd*) + # FreeBSD auxcflags="${cxxversionflag}" - auxlibs="-lm -lstdc++" + auxlibs="-lm" ;; openbsd) # OpenBSD with libc diff --git a/etc/Makefile.arch b/etc/Makefile.arch index b00510a63f7fe..2e04959a2ffe1 100644 --- a/etc/Makefile.arch +++ b/etc/Makefile.arch @@ -286,12 +286,12 @@ LDFLAGS = $(OPT) SOFLAGS = -shared -Wl,-x endif -ifeq ($(ARCH),freebsdx8664) +ifeq ($(findstring freebsd,$(ARCH)),freebsd) # FreeBSD with libc CXX = c++ -CXXFLAGS = $(OPT) -W -Wall -fPIC +CXXFLAGS = $(OPT2) -W -Wall -fPIC LD = $(CXX) -LDFLAGS = $(OPT) +LDFLAGS = $(OPT2) SOFLAGS = -shared -Wl,-x endif From 49560a539ca8b981ea0e9807df0d37bade1e91bc Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Tue, 13 Jun 2023 15:28:38 +0200 Subject: [PATCH 13/21] Remove old freebsd entries --- config/root-config.in | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/config/root-config.in b/config/root-config.in index 41cf84ca69cc7..a9e2d9523d9aa 100755 --- a/config/root-config.in +++ b/config/root-config.in @@ -262,23 +262,6 @@ linuxriscv64) # RISC-V Linux auxlibs="-lm -ldl -rdynamic" ;; -freebsd) - # FreeBSD with libc5 - auxcflags="${cxxversionflag}" - auxlibs="-lm -lg++" - ;; -freebsdx8664) - # FreeBSD with libc5 - auxcflags="${cxxversionflag}" - auxlibs="-lm -lg++" - ;; -freebsd4) - # FreeBSD 4 with glibc - auxcflags="${cxxversionflag}" - auxlibs="-lm -lstdc++" - ;; -freebsd5|freebsd7) - # FreeBSD 5/7 with glibc freebsd*) # FreeBSD auxcflags="${cxxversionflag}" From c829cc9ba869eb34287019e226247bd2b1e6609a Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Thu, 15 Jun 2023 14:41:08 +0200 Subject: [PATCH 14/21] Update core/unix/src/TUnixSystem.cxx Co-authored-by: Javier Lopez-Gomez --- core/unix/src/TUnixSystem.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/unix/src/TUnixSystem.cxx b/core/unix/src/TUnixSystem.cxx index d339c97b6e69e..cd1a0cc2528ca 100644 --- a/core/unix/src/TUnixSystem.cxx +++ b/core/unix/src/TUnixSystem.cxx @@ -420,7 +420,7 @@ static const char *GetExePath() #elif defined(R__SOLARIS) int ret = readlink("/proc/self/path/a.out", buf, kMAXPATHLEN); #elif defined(R__FBSD) - procstat* ps = procstat_open_sysctl(); // + procstat* ps = procstat_open_sysctl(); kinfo_proc* kp = kinfo_getproc(getpid()); int ret{0}; From bbb27ece7607b56987bb130c3bea5cdf066a5c70 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Thu, 15 Jun 2023 14:44:14 +0200 Subject: [PATCH 15/21] Update interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp Co-authored-by: Javier Lopez-Gomez --- .../cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 291a6df48e148..2195b9bd87c18 100644 --- a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -1384,7 +1384,7 @@ namespace cling { return cached_realpath(buf); return cached_realpath(info.dli_fname); # elif defined (__FreeBSD__) - procstat* ps = procstat_open_sysctl(); // + procstat* ps = procstat_open_sysctl(); kinfo_proc* kp = kinfo_getproc(getpid()); char buf[PATH_MAX] = ""; From e8770e805fbb91f7b85951b7b8b6936a7751aff8 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Thu, 15 Jun 2023 14:44:29 +0200 Subject: [PATCH 16/21] Update interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp Co-authored-by: Javier Lopez-Gomez --- .../cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp index 2195b9bd87c18..3e7fbd6dc7aab 100644 --- a/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp +++ b/interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp @@ -56,7 +56,7 @@ # endif #include -# endif +#endif #ifdef LLVM_ON_UNIX #include From 41e6bf339d10ac31d809fed4893b1ad47ef56515 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Thu, 15 Jun 2023 14:45:21 +0200 Subject: [PATCH 17/21] Update io/io/src/TFile.cxx Co-authored-by: Javier Lopez-Gomez --- io/io/src/TFile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index fd230f5c3f045..f64e5c15ca92e 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -170,7 +170,7 @@ ROOT::Internal::RConcurrentHashColl TFile::fgTsSIHashes; #define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0) #endif #ifdef R__FBSD -#define getxattr(path,name,value,size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size) +#define getxattr(path, name, value, size) extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value, size) #endif const Int_t kBEGIN = 100; From 7347184ff7e4c3160da2b3d3170ff9b2239fe152 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Thu, 15 Jun 2023 14:47:04 +0200 Subject: [PATCH 18/21] Update cmake/modules/SetUpFreeBSD.cmake Co-authored-by: Javier Lopez-Gomez --- cmake/modules/SetUpFreeBSD.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/SetUpFreeBSD.cmake b/cmake/modules/SetUpFreeBSD.cmake index c4cfa3e9fe1b3..52c97d28f2971 100644 --- a/cmake/modules/SetUpFreeBSD.cmake +++ b/cmake/modules/SetUpFreeBSD.cmake @@ -1,4 +1,4 @@ -# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. +# Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. # All rights reserved. # # For the licensing terms see $ROOTSYS/LICENSE. From d502f3f8d2df3949ee1ea0dc99c39a57efe85dd2 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Fri, 16 Jun 2023 09:54:52 +0200 Subject: [PATCH 19/21] Update core/dictgen/src/rootcling_impl.cxx Co-authored-by: Javier Lopez-Gomez --- core/dictgen/src/rootcling_impl.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index b52aa57ea9e94..07f7385b31193 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -215,7 +215,7 @@ const char *GetExePath() exepath = buf; } #endif -#if defined R__FBSD || defined __FreeBSD__ +#if defined(R__FBSD) procstat* ps = procstat_open_sysctl(); // kinfo_proc* kp = kinfo_getproc(getpid()); From 0278fe2f2f1b9c3875e1ffd39564bb467cf13a7e Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Fri, 16 Jun 2023 09:58:49 +0200 Subject: [PATCH 20/21] Reuse some code between WIN32 and FreeBSD --- core/foundation/src/FoundationUtils.cxx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/foundation/src/FoundationUtils.cxx b/core/foundation/src/FoundationUtils.cxx index 69f55956f877b..b779072a7fb27 100644 --- a/core/foundation/src/FoundationUtils.cxx +++ b/core/foundation/src/FoundationUtils.cxx @@ -112,30 +112,27 @@ const std::string& GetFallbackRootSys() { static std::string fallback; if (!fallback.empty()) return fallback; + + auto parent_path = [](std::string path) { + return path.substr(0, path.find_last_of("/\\")); + }; + #ifdef WIN32 static char lpFilename[_MAX_PATH]; if (::GetModuleFileNameA( NULL, // handle to module to find filename for lpFilename, // pointer to buffer to receive module path sizeof(lpFilename))) { // size of buffer, in characters - auto parent_path = [](std::string path) { - return path.substr(0, path.find_last_of("/\\")); - }; fallback = parent_path(parent_path(lpFilename)); } #elif defined __FreeBSD__ procstat* ps = procstat_open_sysctl(); // kinfo_proc* kp = kinfo_getproc(getpid()); + char lpFilename[PATH_MAX] = ""; if (kp!=NULL) { - char path_str[PATH_MAX] = ""; - procstat_getpathname(ps, kp, path_str, sizeof(path_str)); - std::string execpath(path_str); - - auto parent_path = [](std::string path) { - return path.substr(0, path.find_last_of("/\\")); - }; - fallback = parent_path(parent_path({path_str})); + procstat_getpathname(ps, kp, lpFilename, sizeof(lpFilename)); + fallback = parent_path(parent_path({lpFilename})); } free(kp); From c37d6099b38c5cbb9bfb912eb112976ee5a3f109 Mon Sep 17 00:00:00 2001 From: Mikolaj Krzewicki Date: Fri, 16 Jun 2023 12:37:33 +0200 Subject: [PATCH 21/21] FreeBSDify rootx --- rootx/CMakeLists.txt | 5 +++++ rootx/src/rootx.cxx | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/rootx/CMakeLists.txt b/rootx/CMakeLists.txt index 2427805aa5f3a..242fcd2dc8836 100644 --- a/rootx/CMakeLists.txt +++ b/rootx/CMakeLists.txt @@ -25,6 +25,11 @@ if(x11) ${X11_Xpm_LIB} ${X11_LIBRARIES} ) + +if (CMAKE_SYSTEM_NAME MATCHES FreeBSD) + target_link_libraries(root PRIVATE util procstat) +endif() + elseif(cocoa) if (cxxmodules) # FIXME: Disable modules for ObjC/ObjC++. It has problems when compiling diff --git a/rootx/src/rootx.cxx b/rootx/src/rootx.cxx index 4403568ff2a19..53106fa5eef70 100644 --- a/rootx/src/rootx.cxx +++ b/rootx/src/rootx.cxx @@ -37,6 +37,14 @@ #include #endif +#ifdef R__FBSD +#include +#include +#include +#include +#include +#endif // R__FBSD + #ifdef __sun # ifndef _REENTRANT # if __SUNPRO_CC > 0x420 @@ -120,6 +128,19 @@ static const char *GetExePath() buf[ret] = 0; exepath = buf; } +#endif +#if defined(R__FBSD) + procstat* ps = procstat_open_sysctl(); // + kinfo_proc* kp = kinfo_getproc(getpid()); + + if (kp!=NULL) { + char path_str[PATH_MAX] = ""; + procstat_getpathname(ps, kp, path_str, sizeof(path_str)); + exepath = path_str; + } + + free(kp); + procstat_close(ps); #endif } return exepath.c_str();