Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
05d64da
Initial set of changes based on the FreeBSD port
mkrzewic Jun 12, 2023
34e51bc
Add SetUpFreeBSD.cmake and use it
mkrzewic Jun 12, 2023
46adf1d
Don't use gnu extensions in sed
mkrzewic Jun 12, 2023
e8e5b0a
Fix linking to crypt lib in FreeBSD
mkrzewic Jun 12, 2023
71345e2
Add the ability to self inspect the exe path on FreeBSD
mkrzewic Jun 8, 2023
aa14c60
Add a poor man's FreeBSD xattr handling, hoping the hardcoded default…
May 17, 2023
203130c
skip trying to load [vdso] as it has no proper path on FreeBSD
mkrzewic Jun 8, 2023
54c732d
Reword defs
mkrzewic Jun 12, 2023
96d1820
Update comment on a workaround for elf.h include in libprostat (FreeBSD)
mkrzewic Jun 12, 2023
af96b2c
Formatting
mkrzewic Jun 12, 2023
65fb8d0
[FreeBSD] Fix ncpu reporting in root-config
mkrzewic Jun 13, 2023
9810d44
Clean up SetupFreeBSD.cmake and define freebsdamd64
mkrzewic Jun 13, 2023
49560a5
Remove old freebsd entries
mkrzewic Jun 13, 2023
c829cc9
Update core/unix/src/TUnixSystem.cxx
mkrzewic Jun 15, 2023
bbb27ec
Update interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp
mkrzewic Jun 15, 2023
e8770e8
Update interpreter/cling/lib/Interpreter/DynamicLibraryManagerSymbol.cpp
mkrzewic Jun 15, 2023
41e6bf3
Update io/io/src/TFile.cxx
mkrzewic Jun 15, 2023
7347184
Update cmake/modules/SetUpFreeBSD.cmake
mkrzewic Jun 15, 2023
d502f3f
Update core/dictgen/src/rootcling_impl.cxx
mkrzewic Jun 16, 2023
0278fe2
Reuse some code between WIN32 and FreeBSD
mkrzewic Jun 16, 2023
c37d609
FreeBSDify rootx
mkrzewic Jun 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/unix/compiledata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/CheckCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
97 changes: 97 additions & 0 deletions cmake/modules/SetUpFreeBSD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (C) 1995-2023, 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)
set(ROOT_ARCHITECTURE freebsdamd64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES i686)
set(FP_MATH_FLAGS "-msse2 -mfpmath=sse")
set(ROOT_ARCHITECTURE freebsdi686)
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 freebsdppc64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390x)
set(ROOT_ARCHITECTURE freebsds390x)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES s390)
set(ROOT_ARCHITECTURE freebsds390)
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()

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)
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()
endif()
37 changes: 22 additions & 15 deletions config/root-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,10 @@ linuxriscv64)
# RISC-V Linux
auxlibs="-lm -ldl -rdynamic"
;;
freebsd)
# FreeBSD with libc5
freebsd*)
# FreeBSD
auxcflags="${cxxversionflag}"
auxlibs="-lm -lg++"
;;
freebsd4)
# FreeBSD 4 with glibc
auxcflags="${cxxversionflag}"
auxlibs="-lm -lstdc++"
;;
freebsd5|freebsd7)
# FreeBSD 5/7 with glibc
auxcflags="${cxxversionflag}"
auxlibs="-lm -lstdc++"
auxlibs="-lm"
;;
openbsd)
# OpenBSD with libc
Expand Down Expand Up @@ -368,7 +358,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"

Expand Down Expand Up @@ -784,9 +788,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)
;;
Expand Down
4 changes: 4 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/ginclude>
)
Expand Down
21 changes: 21 additions & 0 deletions core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
#include <mach-o/dyld.h>
#endif

#ifdef R__FBSD
#include <sys/param.h>
#include <sys/user.h>
#include <sys/types.h>
#include <libutil.h>
#include <libprocstat.h>
#endif // R__FBSD

#if !defined(R__WIN32)
#include <limits.h>
#include <unistd.h>
Expand Down Expand Up @@ -207,6 +215,19 @@ const char *GetExePath()
exepath = buf;
}
#endif
#if defined(R__FBSD)
procstat* ps = procstat_open_sysctl(); //
kinfo_proc* kp = kinfo_getproc(getpid());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some other usages of the procfs filesystem typically mounted on /proc on Linux, namely in:

  • The proof/, rootx/ and bindings/pyroot/cppyy/ directories
  • The config/thisroot.sh file

Maybe we should take a look into those too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config/thisroot.sh should work as it is
rootx I'll fix, but is there no common library/place to define GetExePath (and the like) once for all components?
proof and python I'll leave for later as I have no use for those. Someone will contribute a patch if there is need:)


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);
Expand Down
3 changes: 3 additions & 0 deletions core/foundation/inc/ThreadLocalStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 27 additions & 3 deletions core/foundation/src/FoundationUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@

#include <errno.h>
#include <string.h>

#ifdef _WIN32
#include <direct.h>
#include <Windows4Root.h>
#else
#include <unistd.h>
#endif // _WIN32

#ifdef __FreeBSD__
#include <sys/syslimits.h>
#include <sys/param.h>
#include <sys/user.h>
#include <sys/types.h>
#include <libutil.h>
#include <libprocstat.h>
#endif // __FreeBSD__

namespace ROOT {
namespace FoundationUtils {
std::string GetCurrentDir()
Expand Down Expand Up @@ -102,17 +112,31 @@ 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) {
procstat_getpathname(ps, kp, lpFilename, sizeof(lpFilename));
fallback = parent_path(parent_path({lpFilename}));
}

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
Expand Down
5 changes: 5 additions & 0 deletions core/metacling/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

11 changes: 7 additions & 4 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ clang/LLVM technology.
#include <dlfcn.h>
#endif

#ifdef R__LINUX
#if defined(R__LINUX) || defined(R__FBSD)
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
Expand Down Expand Up @@ -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`.
Expand All @@ -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)
Expand All @@ -3290,7 +3293,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


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3337,7 +3340,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;

Expand Down
5 changes: 5 additions & 0 deletions core/metacling/src/rootclingTCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

#undef R__DLLEXPORT

#ifdef __FreeBSD__
char* __progname;
char** environ;
Comment on lines +24 to +25
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are extern, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, this is a "legacy" fix from the port maintainer, it is needed and sufficient (it seems). I think maybe for some reason the symbols needed to be visible for lld, possibly some subtle difference with ld.

#endif

#include "TROOT.h"
#include "TCling.h"

Expand Down
3 changes: 3 additions & 0 deletions core/rootcling_stage1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions core/unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading