fix building native component for FreeBSD (#2419)
authorThefrank <1910378+Thefrank@users.noreply.github.com>
Wed, 7 Jul 2021 18:05:16 +0000 (11:05 -0700)
committerGitHub <noreply@github.com>
Wed, 7 Jul 2021 18:05:16 +0000 (11:05 -0700)
Fix building native under FreeBSD

Co-authored-by: TheFrank <none>
compileoptions.cmake
src/SOS/dbgutil/elfreader.cpp
src/SOS/dbgutil/elfreader.h
src/SOS/extensions/hostcoreclr.cpp
src/SOS/lldbplugin/CMakeLists.txt
src/pal/src/misc/sysinfo.cpp

index 7bc7afbbc8744dd47e849f0b9f49da30436577f7..b31f26568942c6adaeb07b8c9a5ada6ca96469ac 100644 (file)
@@ -79,6 +79,11 @@ if(CLR_CMAKE_PLATFORM_UNIX_ARM)
    endif(ARM_SOFTFP)
 endif(CLR_CMAKE_PLATFORM_UNIX_ARM)
 
+if(CLR_CMAKE_PLATFORM_FREEBSD)
+  add_compile_options(-Wno-macro-redefined)
+  add_compile_options(-Wno-pointer-to-int-cast)
+endif(CLR_CMAKE_PLATFORM_FREEBSD)
+
 if (WIN32)
   # Compile options for targeting windows
 
index a8d00fa311791a3de7775570a5615aca40ce8a56..0deebf945609a72ebe79568736da3b0cfdf17f06 100644 (file)
@@ -393,10 +393,11 @@ ElfReader::EnumerateLinkMapEntries(Elf_Dyn* dynamicAddr)
             for (; i < PATH_MAX; i++)
             {
                 char ch;
-                if (!ReadMemory(map.l_name + i, &ch, sizeof(ch))) {
-                    TRACE("DSO: ReadMemory link_map name %p + %d FAILED\n", map.l_name, i);
+               char* l_name = const_cast<char*>(map.l_name);
+               if (!ReadMemory(l_name + i, &ch, sizeof(ch))) {
+                   TRACE("DSO: ReadMemory link_map name %p + %d FAILED\n", map.l_name, i);
                     break;
-                }
+               }
                 if (ch == '\0') {
                     break;
                 }
index 93cc57963f3634460d16a0208c90862067507f9a..fe1648db4e41f23eb62a448f8a19f8827b1b7cda 100644 (file)
@@ -63,7 +63,11 @@ private:
     bool EnumerateLinkMapEntries(ElfW(Dyn)* dynamicAddr);
 #endif
     bool EnumerateProgramHeaders(ElfW(Phdr)* phdrAddr, int phnum, uint64_t baseAddress, uint64_t* ploadbias, ElfW(Dyn)** pdynamicAddr);
+#ifdef __FreeBSD__
+    virtual void VisitModule(caddr_t baseAddress, std::string& moduleName) { };
+#else
     virtual void VisitModule(uint64_t baseAddress, std::string& moduleName) { };
+#endif
     virtual void VisitProgramHeader(uint64_t loadbias, uint64_t baseAddress, ElfW(Phdr)* phdr) { };
     virtual bool ReadMemory(void* address, void* buffer, size_t size) = 0;
     virtual void Trace(const char* format, ...) { };
index b7d823bcc19531b38d5293133e38f95b67d23a75..4d22a48bc02862bae5342d8c7b868aecf614e10f 100644 (file)
 #include <mach-o/dyld.h>
 #endif
 
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
 #include "palclr.h"
 #include "arrayholder.h"
 #include "coreclrhost.h"
@@ -412,8 +417,8 @@ static HRESULT GetHostRuntime(std::string& coreClrPath, std::string& hostRuntime
         else 
         {
 #ifdef FEATURE_PAL
-#if defined (__FreeBSD__) || defined(__NetBSD__)
-            TraceError("Hosting on FreeBSD or NetBSD not supported\n");
+#if defined(__NetBSD__)
+            TraceError("Hosting on NetBSD not supported\n");
             return E_FAIL;
 #else
             char* line = nullptr;
@@ -446,7 +451,7 @@ static HRESULT GetHostRuntime(std::string& coreClrPath, std::string& hostRuntime
                     }
                 }
             }
-#endif // defined (__FreeBSD__) || defined(__NetBSD__)
+#endif // defined(__NetBSD__)
 #else
             ArrayHolder<CHAR> programFiles = new CHAR[MAX_LONGPATH];
             if (GetEnvironmentVariableA("PROGRAMFILES", programFiles, MAX_LONGPATH) == 0)
index b850a7886a9c8828d84a493165fc63fa9bb71cf8..9865a6f8a5bcd49ed1dfcd039585011a068fac58 100644 (file)
@@ -114,6 +114,10 @@ else()
     #FreeBSD
     find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm39/include")
     find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm38/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm12/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm11/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm10/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm90/include")
 
     if(LLDB_H STREQUAL LLDB_H-NOTFOUND)
        if(REQUIRE_LLDBPLUGIN)
index 45b6b3bdb811abe1565a4af55b24292bf590c0d6..214e8ccd38da4aaf12cd2b43c5d8c4330259a819 100644 (file)
@@ -35,6 +35,10 @@ Revision History:
 #error Either sysctl or sysconf is required for GetSystemInfo.
 #endif
 
+#if defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
+
 #if HAVE_SYSINFO
 #include <sys/sysinfo.h>
 #endif