From d16747cf6ccb077d4ae50e9135c88604f1fad9c1 Mon Sep 17 00:00:00 2001
From: Ryan Kurtz
Date: Tue, 16 Jan 2024 08:26:46 -0500
Subject: [PATCH] GP-4235: Adding the means to build and find native components
on FreeBSD
---
GPL/DemanglerGnu/build.gradle | 2 ++
GPL/nativeBuildProperties.gradle | 5 +++++
GPL/nativePlatforms.gradle | 20 ++++++++++++++++++-
.../Features/Decompiler/buildNatives.gradle | 2 ++
.../main/java/ghidra/framework/Platform.java | 8 +++++++-
.../ghidra/framework/OperatingSystem.java | 2 +-
.../application/ApplicationUtilities.java | 2 ++
GhidraDocs/InstallationGuide.html | 8 ++++----
8 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/GPL/DemanglerGnu/build.gradle b/GPL/DemanglerGnu/build.gradle
index 255fd56a5c..174747549f 100644
--- a/GPL/DemanglerGnu/build.gradle
+++ b/GPL/DemanglerGnu/build.gradle
@@ -81,6 +81,7 @@ model {
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
+ targetPlatform "freebsd_x86_64"
sources {
c {
source {
@@ -102,6 +103,7 @@ model {
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
+ targetPlatform "freebsd_x86_64"
sources {
c {
source {
diff --git a/GPL/nativeBuildProperties.gradle b/GPL/nativeBuildProperties.gradle
index 5e9c33f4eb..6ba0409b6a 100644
--- a/GPL/nativeBuildProperties.gradle
+++ b/GPL/nativeBuildProperties.gradle
@@ -52,6 +52,11 @@ model {
}
}
}
+ if (isCurrentFreeBSD()) {
+ gcc(Gcc) {
+ target("freebsd_x86_64")
+ }
+ }
if (isCurrentWindows() && VISUAL_STUDIO_INSTALL_DIR) {
// specify installDir because Gradle doesn't find VS Build Tools.
// See https://github.com/gradle/gradle-native/issues/617#issuecomment-575735288
diff --git a/GPL/nativePlatforms.gradle b/GPL/nativePlatforms.gradle
index a75cf48a5d..24d540f10a 100644
--- a/GPL/nativePlatforms.gradle
+++ b/GPL/nativePlatforms.gradle
@@ -24,7 +24,8 @@ project.ext.PLATFORMS = [
[name: "linux_x86_64", os: "linux", arch: "x86_64"],
[name: "linux_arm_64", os: "linux", arch: "arm64"],
[name: "mac_x86_64", os: "osx", arch: "x86_64"],
- [name: "mac_arm_64", os: "osx", arch: "arm64"]
+ [name: "mac_arm_64", os: "osx", arch: "arm64"],
+ [name: "freebsd_x86_64", os: "freebsd", arch: "x86_64"]
]
/*********************************************************************************
@@ -51,6 +52,9 @@ ext.getCurrentPlatformName = {
case ~/Mac OS X.*/:
os = "mac"
break
+ case ~/FreeBSD.*/:
+ os = "freebsd"
+ break
default:
throw new GradleException("Unrecognized platform operating system: $os")
}
@@ -112,6 +116,20 @@ ext.isCurrentMac = {
return isMac(getCurrentPlatformName())
}
+/*********************************************************************************
+ * Returns true if the given platform is FreeBSD.
+ *********************************************************************************/
+ext.isFreeBSD = { platform_name ->
+ return platform_name.startsWith("freebsd")
+}
+
+/*********************************************************************************
+ * Returns true if the current platform is FreeBSD.
+ *********************************************************************************/
+ext.isCurrentFreeBSD = {
+ return isFreeBSD(getCurrentPlatformName())
+}
+
/*********************************************************************************
* Returns true if the given platform is Windows.
*********************************************************************************/
diff --git a/Ghidra/Features/Decompiler/buildNatives.gradle b/Ghidra/Features/Decompiler/buildNatives.gradle
index 9cf660e915..25a90a11e9 100644
--- a/Ghidra/Features/Decompiler/buildNatives.gradle
+++ b/Ghidra/Features/Decompiler/buildNatives.gradle
@@ -43,6 +43,7 @@ model {
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
+ targetPlatform "freebsd_x86_64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
@@ -148,6 +149,7 @@ model {
targetPlatform "linux_arm_64"
targetPlatform "mac_x86_64"
targetPlatform "mac_arm_64"
+ targetPlatform "freebsd_x86_64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
index 562ca606af..68f5d476fb 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
@@ -65,6 +65,11 @@ public enum Platform {
*/
MAC_ARM_64(OperatingSystem.MAC_OS_X, Architecture.ARM_64, "mac_arm_64", ".dylib", ""),
+ /**
+ * Identifies a FreeBSD x86 64-bit OS.
+ */
+ FREEBSD_X86_64(OperatingSystem.FREE_BSD, Architecture.X86_64, "freebsd_x86_64", ".so", ""),
+
/**
* Identifies an unsupported OS.
*/
@@ -199,7 +204,8 @@ public enum Platform {
*/
public List getAdditionalLibraryPaths() {
List paths = new ArrayList();
- if (operatingSystem == OperatingSystem.LINUX) {
+ if (operatingSystem == OperatingSystem.LINUX ||
+ operatingSystem == OperatingSystem.FREE_BSD) {
paths.add("/bin");
paths.add("/lib");
paths.add("/lib64");
diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
index 1abe4d34b2..e803f338a1 100644
--- a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/OperatingSystem.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +19,7 @@ public enum OperatingSystem {
WINDOWS("Windows"),
LINUX("Linux"),
MAC_OS_X("Mac OS X"),
+ FREE_BSD("FreeBSD"),
UNSUPPORTED("Unsupported Operating System");
/**
diff --git a/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java b/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
index 261b0ddcd3..16d354cc64 100644
--- a/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
+++ b/Ghidra/Framework/Utility/src/main/java/utility/application/ApplicationUtilities.java
@@ -225,6 +225,7 @@ public class ApplicationUtilities {
return createDir(switch (OperatingSystem.CURRENT_OPERATING_SYSTEM) {
case WINDOWS -> new File(getEnvFile("LOCALAPPDATA", true), appName);
case LINUX -> new File("/var/tmp/" + userDirName);
+ case FREE_BSD -> new File("/var/tmp/" + userDirName);
case MAC_OS_X -> new File("/var/tmp/" + userDirName);
default -> throw new FileNotFoundException(
"Failed to find the user cache directory: Unsupported operating system.");
@@ -281,6 +282,7 @@ public class ApplicationUtilities {
return createDir(switch (OperatingSystem.CURRENT_OPERATING_SYSTEM) {
case WINDOWS -> new File(getEnvFile("APPDATA", true), versionedSubdir);
case LINUX -> new File(userHomeDir, ".config/" + versionedSubdir);
+ case FREE_BSD -> new File(userHomeDir, ".config/" + versionedSubdir);
case MAC_OS_X -> new File(userHomeDir, "Library/" + versionedSubdir);
default -> throw new FileNotFoundException(
"Failed to find the user settings directory: Unsupported operating system.");
diff --git a/GhidraDocs/InstallationGuide.html b/GhidraDocs/InstallationGuide.html
index 9dffdc2c23..3c47400b84 100644
--- a/GhidraDocs/InstallationGuide.html
+++ b/GhidraDocs/InstallationGuide.html
@@ -18,7 +18,7 @@
Ghidra Installation Guide
-The installation information provided is effective as of Ghidra 10.2 and is subject to change with
+The installation information provided is effective as of Ghidra 11.1 and is subject to change with
future releases.
@@ -310,20 +310,20 @@ Ghidra release includes native binaries for the following platforms:
Windows x86 64-bit
Linux x86 64-bit
macOS x86 64-bit
- macOS ARM 64-bit (x86 using Rosetta translation)
+ macOS ARM 64-bit
Ghidra supports running on the following additional platforms with user-built native binaries:
- Linux ARM 64-bit
- - macOS ARM 64-bit (Apple silicon)
+ - FreeBSD x86 64-bit (no debugger support)
In order to build native binaries for your platform, you will need the following installed on your
system: