Skip to content

Instantly share code, notes, and snippets.

@astarasikov
Last active February 27, 2021 01:10
Show Gist options
  • Save astarasikov/b598592ddd6637a50ba143059d1f4a90 to your computer and use it in GitHub Desktop.
Save astarasikov/b598592ddd6637a50ba143059d1f4a90 to your computer and use it in GitHub Desktop.
From 10c8286b202c4f086212caaa5b6a26266b940d0b Mon Sep 17 00:00:00 2001
From: Alexander Tarasikov <[email protected]>
Date: Fri, 26 Feb 2021 03:47:04 +0100
Subject: [PATCH] Apply ARM64 patch from Longhorn
Base patch from
https://threedots.ovh/blog/2021/01/ghidra-for-arm-64-bit-linux-systems/
Minor changes to fix compilation for OSX ARM64
---
GPL/CabExtract/Module.manifest | 2 ++
GPL/CabExtract/build.gradle | 4 +--
GPL/DemanglerGnu/Module.manifest | 5 ++-
GPL/DemanglerGnu/build.gradle | 35 +++++++++++++++++++
GPL/GnuDisassembler/buildGdis.gradle | 12 +++++--
GPL/gpl.gradle | 13 ++++++-
GPL/nativeBuildProperties.gradle | 12 +++++++
Ghidra/Features/Decompiler/build.gradle | 23 ++++++++++++
.../Decompiler/src/decompile/cpp/Makefile | 6 ++--
.../Decompiler/src/decompile/cpp/types.h | 16 +++++++++
.../java/ghidra/framework/Architecture.java | 1 +
.../main/java/ghidra/framework/Platform.java | 15 ++++++++
Ghidra/RuntimeScripts/Linux/server/ghidraSvr | 2 +-
GhidraBuild/Skeleton/certification.manifest | 3 ++
.../GhidraAdvancedDevelopment.html | 2 +-
build.gradle | 12 ++++++-
gradle/root/distribution.gradle | 3 ++
gradle/support/ip.gradle | 2 +-
18 files changed, 156 insertions(+), 12 deletions(-)
diff --git a/GPL/CabExtract/Module.manifest b/GPL/CabExtract/Module.manifest
index d98fc28fe..34eee0c4d 100644
--- a/GPL/CabExtract/Module.manifest
+++ b/GPL/CabExtract/Module.manifest
@@ -1,2 +1,4 @@
MODULE FILE LICENSE: os/linux64/cabextract GPL 3
+MODULE FILE LICENSE: os/linuxarm64/cabextract GPL 3
MODULE FILE LICENSE: os/osx64/cabextract GPL 3
+MODULE FILE LICENSE: os/osxarm64/cabextract GPL 3
diff --git a/GPL/CabExtract/build.gradle b/GPL/CabExtract/build.gradle
index 95b36dd4d..5f429b841 100644
--- a/GPL/CabExtract/build.gradle
+++ b/GPL/CabExtract/build.gradle
@@ -20,7 +20,7 @@ project.ext.cabextract = "cabextract-1.6"
* The cabextract tool requires that its 'configure' script is called before make.
*********************************************************************************/
def currentPlatform = getCurrentPlatformName()
-if (['linux64', 'osx64'].contains(currentPlatform)) {
+if (['linux64', 'linuxarm64', 'osx64', 'osxarm64'].contains(currentPlatform)) {
def makeName = "${currentPlatform}CabExtractMake"
@@ -57,4 +57,4 @@ if (['linux64', 'osx64'].contains(currentPlatform)) {
delete file("build/unpack/${cabextract}")
}
}
-}
\ No newline at end of file
+}
diff --git a/GPL/DemanglerGnu/Module.manifest b/GPL/DemanglerGnu/Module.manifest
index edf7b2793..5ce8fa198 100644
--- a/GPL/DemanglerGnu/Module.manifest
+++ b/GPL/DemanglerGnu/Module.manifest
@@ -1,3 +1,6 @@
MODULE FILE LICENSE: os/linux64/demangler_gnu GPL 3
+MODULE FILE LICENSE: os/linuxarm64/demangler_gnu GPL 3
MODULE FILE LICENSE: os/osx64/demangler_gnu GPL 3
-MODULE FILE LICENSE: os/win64/demangler_gnu.exe GPL 3
\ No newline at end of file
+MODULE FILE LICENSE: os/osxarm64/demangler_gnu GPL 3
+MODULE FILE LICENSE: os/win64/demangler_gnu.exe GPL 3
+MODULE FILE LICENSE: os/winarm64/demangler_gnu.exe GPL 3
diff --git a/GPL/DemanglerGnu/build.gradle b/GPL/DemanglerGnu/build.gradle
index 624421568..c6f5fe70a 100644
--- a/GPL/DemanglerGnu/build.gradle
+++ b/GPL/DemanglerGnu/build.gradle
@@ -22,6 +22,23 @@ def srcVersion24 = "src/demangler_gnu_v2_24"
* Defines the platforms we have to support in Ghidra. This model is used
* for all native builds and should be extended by each module as-needed.
****************************************************************************/
+model {
+toolChains {
+ clang(Clang) {
+ target("osxarm64") {
+ cCompiler.executable = "/usr/bin/clang"
+ cppCompiler.executable = "/usr/bin/clang++"
+ }
+ }
+ gcc(Gcc){
+ target("linuxarm64") {
+ cCompiler.executable = "/usr/bin/gcc"
+ cppCompiler.executable = "/usr/bin/g++"
+ }
+ }
+}
+}
+
model {
// define the platforms that we support in ghidra
@@ -30,14 +47,26 @@ model {
architecture 'x86_64'
operatingSystem 'windows'
}
+ winarm64 {
+ architecture 'arm64'
+ operatingSystem 'windows'
+ }
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
+ linuxarm64 {
+ architecture 'arm64'
+ operatingSystem 'linux'
+ }
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
+ osxarm64 {
+ architecture 'arm64'
+ operatingSystem 'osx'
+ }
}
}
@@ -98,8 +127,11 @@ model {
components {
demangler_gnu_v2_33_1(NativeExecutableSpec) {
targetPlatform "win64"
+ targetPlatform "winarm64"
targetPlatform "linux64"
+ targetPlatform "linuxarm64"
targetPlatform "osx64"
+ targetPlatform "osxarm64"
sources {
c {
source {
@@ -117,8 +149,11 @@ model {
//
demangler_gnu_v2_24(NativeExecutableSpec) {
targetPlatform "win64"
+ targetPlatform "winarm64"
targetPlatform "linux64"
+ targetPlatform "linuxarm64"
targetPlatform "osx64"
+ targetPlatform "osxarm64"
sources {
c {
source {
diff --git a/GPL/GnuDisassembler/buildGdis.gradle b/GPL/GnuDisassembler/buildGdis.gradle
index 2859dd073..b9d1badf1 100644
--- a/GPL/GnuDisassembler/buildGdis.gradle
+++ b/GPL/GnuDisassembler/buildGdis.gradle
@@ -6,7 +6,7 @@
defaultTasks 'assemble'
-ext.supportedPlatforms = ['osx64', 'linux64']
+ext.supportedPlatforms = ['osx64', 'osxarm64', 'linux64', 'linuxarm64']
ext.binutilsResource = new File("${binutilsLocation}/${binutils}.tar.bz2")
@@ -27,10 +27,18 @@ model {
architecture 'x86_64'
operatingSystem 'linux'
}
+ linuxarm64 {
+ architecture 'arm64'
+ operatingSystem 'linux'
+ }
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
+ osxarm64 {
+ architecture 'arm64'
+ operatingSystem 'osx'
+ }
}
components {
@@ -61,7 +69,7 @@ model {
}
tasks.compileGdisOsx64ExecutableGdisC {
- dependsOn 'copyBinutilsArtifcats_osx64'
+ dependsOn 'copyBinutilsArtifcats_osxarm64'
}
tasks.compileGdisLinux64ExecutableGdisC {
dependsOn 'copyBinutilsArtifcats_linux64'
diff --git a/GPL/gpl.gradle b/GPL/gpl.gradle
index 9428b3bdf..90bc6f874 100644
--- a/GPL/gpl.gradle
+++ b/GPL/gpl.gradle
@@ -6,7 +6,7 @@ project.ext.BIN_REPO = file("../../../ghidra.bin").absolutePath
* Create a set containing all the platforms we need when building native
* artifacts.
****************************************************************************/
-project.ext.set("OS_NAMES", ["osx64", "win32", "win64", "linux64"])
+project.ext.set("OS_NAMES", ["osx64", "osxarm64", "win32", "win64", "winarm64", "linux64", "linuxarm64"])
/****************************************************************************
* Establish Visual Studio configuration environment for Windows native builds
@@ -24,6 +24,7 @@ ext.getCurrentPlatformName = {
boolean isX86_32 = archName.equals("x86") || archName.equals("i386");
boolean isX86_64 = archName.equals("x86_64") || archName.equals("amd64");
+ boolean isARM64 = archName.equals("aarch64") || archName.equals("arm64");
if (osName.startsWith("Windows")) {
if (isX86_32) {
@@ -32,17 +33,27 @@ ext.getCurrentPlatformName = {
else if (isX86_64) {
return 'win64'
}
+ else if (isARM64) {
+ return 'winarm64'
+ }
}
else if (osName.startsWith("Linux")) {
if (isX86_64) {
return 'linux64'
}
+ else if (isARM64) {
+ return 'linuxarm64'
+ }
}
else if (osName.startsWith("Mac OS X")) {
if (isX86_64) {
return 'osx64'
}
+ else if (isARM64) {
+ return 'osxarm64'
+ }
}
+
throw new GradleException("Unrecognized current platform -> osName = $osName, archName = $archName")
}
/******************************************************************************************
diff --git a/GPL/nativeBuildProperties.gradle b/GPL/nativeBuildProperties.gradle
index 759e2c0ce..1b84663bf 100644
--- a/GPL/nativeBuildProperties.gradle
+++ b/GPL/nativeBuildProperties.gradle
@@ -31,14 +31,26 @@ model {
architecture 'x86_64'
operatingSystem 'windows'
}
+ winarm64 {
+ architecture 'arm64'
+ operatingSystem 'windows'
+ }
linux64 {
architecture 'x86_64'
operatingSystem 'linux'
}
+ linuxarm64 {
+ architecture 'arm64'
+ operatingSystem 'linux'
+ }
osx64 {
architecture 'x86_64'
operatingSystem 'osx'
}
+ osxarm64 {
+ architecture 'arm64'
+ operatingSystem 'osx'
+ }
}
}
diff --git a/Ghidra/Features/Decompiler/build.gradle b/Ghidra/Features/Decompiler/build.gradle
index 2ee427014..f5dc5e4d1 100644
--- a/Ghidra/Features/Decompiler/build.gradle
+++ b/Ghidra/Features/Decompiler/build.gradle
@@ -8,6 +8,23 @@ apply plugin: 'eclipse'
eclipse.project.name = 'Features Decompiler'
+model {
+toolChains {
+ clang(Clang) {
+ target("osxarm64") {
+ cCompiler.executable = "/usr/bin/clang"
+ cppCompiler.executable = "/usr/bin/clang++"
+ }
+ }
+ gcc(Gcc){
+ target("linuxarm64") {
+ cCompiler.executable = "/usr/bin/gcc"
+ cppCompiler.executable = "/usr/bin/g++"
+ }
+ }
+}
+}
+
dependencies {
compile project(':Base')
compile project(':SoftwareModeling')
@@ -372,8 +389,11 @@ model {
// these tell gradle for which platforms to build a decompiler executable.
targetPlatform "win64"
+ targetPlatform "winarm64"
targetPlatform "linux64"
+ targetPlatform "linuxarm64"
targetPlatform "osx64"
+ targetPlatform "osxarm64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
@@ -470,8 +490,11 @@ model {
sleigh(NativeExecutableSpec) {
targetPlatform "win64"
+ targetPlatform "winarm64"
targetPlatform "linux64"
+ targetPlatform "linuxarm64"
targetPlatform "osx64"
+ targetPlatform "osxarm64"
sources {
cpp {
// NOTE: The bison/flex generated files are assumed to be up-to-date.
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile b/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
index f422f4b5b..844ecb35d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/Makefile
@@ -20,6 +20,8 @@ endif
ifeq ($(ARCH),x86_64)
ARCH_TYPE=-m64
OSDIR=linux64
+else ifeq ($(ARCH),aarch64)
+ OSDIR=linuxarm64
else
ARCH_TYPE=-m32
OSDIR=linux32
@@ -28,9 +30,9 @@ endif
ifeq ($(OS),Darwin)
MAKE_STATIC=
- ARCH_TYPE=-arch x86_64
+ ARCH_TYPE=-arch arm64
ADDITIONAL_FLAGS=-mmacosx-version-min=10.6 -w
- OSDIR=osx64
+ OSDIR=osxarm64
endif
CC=gcc
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h b/Ghidra/Features/Decompiler/src/decompile/cpp/types.h
index d10906637..2b1795d6b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/types.h
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/types.h
@@ -101,6 +101,22 @@ typedef char int1;
typedef uint8 uintp;
#endif
+#if defined (__linux__) && defined (__aarch64__)
+#define HOST_ENDIAN 0
+typedef unsigned int uintm;
+typedef int intm;
+typedef unsigned long uint8;
+typedef long int8;
+typedef unsigned int uint4;
+typedef int int4;
+typedef unsigned short uint2;
+typedef short int2;
+typedef unsigned char uint1;
+/* on the Arm AAPCS ABI used by Linux, char is an unsigned type. */
+typedef signed char int1;
+typedef uint8 uintp;
+#endif
+
#if defined(_WINDOWS)
#if defined(_WIN64)
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Architecture.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Architecture.java
index 1ed37ddd8..a2b71cf83 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Architecture.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Architecture.java
@@ -19,6 +19,7 @@ package ghidra.framework;
public enum Architecture {
X86("x86", "i386"),
X86_64("x86_64", "amd64"),
+ ARM64("aarch64", "arm64"),
POWERPC("ppc"),
POWERPC_64("ppc64"),
UNKNOWN("Unknown Architecture");
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 60b36878f..2a345f257 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/Platform.java
@@ -35,6 +35,11 @@ public enum Platform {
*/
WIN_64(OperatingSystem.WINDOWS, Architecture.X86_64, "win64", ".dll", ".exe"),
+ /**
+ * Identifies a Windows on Arm 64-bit OS
+ */
+ WIN_ARM64(OperatingSystem.WINDOWS, Architecture.ARM64, "winarm64", ".dll", ".exe"),
+
/**
* Identifies a Windows OS, the architecture for which we do not know or have not encountered
*/
@@ -50,6 +55,11 @@ public enum Platform {
*/
LINUX_64(OperatingSystem.LINUX, Architecture.X86_64, "linux64", ".so", ""),
+ /**
+ * Identifies a Linux OS arm64
+ */
+ LINUX_ARM64(OperatingSystem.LINUX, Architecture.ARM64, "linuxarm64", ".so", ""),
+
/**
* Identifies a Linux OS, the architecture for which we do not know or have not encountered
*/
@@ -65,6 +75,11 @@ public enum Platform {
*/
MAC_OSX_64(OperatingSystem.MAC_OS_X, Architecture.X86_64, "osx64", ".dylib", ""),
+ /**
+ * Identifies macOS on Apple processors
+ */
+ MAC_OSX_ARM64(OperatingSystem.MAC_OS_X, Architecture.ARM64, "osxarm64", ".dylib", ""),
+
/**
* Identifies a Mac OS, the architecture for which we do not know or have not encountered
*/
diff --git a/Ghidra/RuntimeScripts/Linux/server/ghidraSvr b/Ghidra/RuntimeScripts/Linux/server/ghidraSvr
index 25e660ca4..b885892f4 100755
--- a/Ghidra/RuntimeScripts/Linux/server/ghidraSvr
+++ b/Ghidra/RuntimeScripts/Linux/server/ghidraSvr
@@ -70,7 +70,7 @@ SCRIPT_DIR="$(pwd)"
OS="$(uname -s)"
if [ "$OS" = "Darwin" ]; then
- OS_DIRNAME="osx64"
+ OS_DIRNAME="osxarm64"
else
OS_DIRNAME="linux64"
fi
diff --git a/GhidraBuild/Skeleton/certification.manifest b/GhidraBuild/Skeleton/certification.manifest
index e0904abf9..e9a255580 100644
--- a/GhidraBuild/Skeleton/certification.manifest
+++ b/GhidraBuild/Skeleton/certification.manifest
@@ -15,8 +15,11 @@ extension.properties||GHIDRA||||END|
ghidra_scripts/README.txt||GHIDRA||||END|
lib/README.txt||GHIDRA||||END|
os/linux64/README.txt||GHIDRA||||END|
+os/linuxarm64/README.txt||GHIDRA||||END|
os/osx64/README.txt||GHIDRA||||END|
+os/osxarm64/README.txt||GHIDRA||||END|
os/win64/README.txt||GHIDRA||||END|
+os/winarm64/README.txt||GHIDRA||||END|
src/main/help/help/TOC_Source.xml||GHIDRA||||END|
src/main/help/help/topics/skeleton/help.html||GHIDRA||||END|
src/main/resources/images/README.txt||GHIDRA||||END|
diff --git a/GhidraDocs/GhidraClass/AdvancedDevelopment/GhidraAdvancedDevelopment.html b/GhidraDocs/GhidraClass/AdvancedDevelopment/GhidraAdvancedDevelopment.html
index f0a20ac61..96fffe761 100644
--- a/GhidraDocs/GhidraClass/AdvancedDevelopment/GhidraAdvancedDevelopment.html
+++ b/GhidraDocs/GhidraClass/AdvancedDevelopment/GhidraAdvancedDevelopment.html
@@ -430,7 +430,7 @@
<ul>
<li>Linux x86_64 natives</li>
</ul>
- <li><folder class="icon">osx64/</folder></li>
+ <li><folder class="icon">osxarm64/</folder></li>
<ul>
<li>Mac OSX x86_64 natives</li>
</ul>
diff --git a/build.gradle b/build.gradle
index ecd372c4a..1858d21a0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -78,7 +78,7 @@ else {
* project.OS_NAMES.each {...}
****************************************************************************/
-project.ext.set("OS_NAMES", ["osx64", "win32", "win64", "linux64"])
+project.ext.set("OS_NAMES", ["osx64", "osxarm64", "win32", "win64", "winarm64", "linux64", "linuxarm64"])
/****************************************************************************
* Establish Visual Studio configuration environment for Windows native builds
@@ -265,6 +265,7 @@ String getCurrentPlatformName() {
boolean isX86_32 = archName.equals("x86") || archName.equals("i386");
boolean isX86_64 = archName.equals("x86_64") || archName.equals("amd64");
+ boolean isARM64 = archName.equals("aarch64") || archName.equals("arm64");
boolean isAARCH_64 = archName.equals("aarch64");
if (osName.startsWith("Windows")) {
@@ -274,16 +275,25 @@ String getCurrentPlatformName() {
else if (isX86_64) {
return 'win64'
}
+ else if (isARM64) {
+ return 'winarm64'
+ }
}
else if (osName.startsWith("Linux")) {
if (isX86_64) {
return 'linux64'
}
+ else if (isARM64) {
+ return 'linuxarm64'
+ }
}
else if (osName.startsWith("Mac OS X")) {
if (isX86_64) {
return 'osx64'
}
+ else if (isARM64) {
+ return 'osxarm64'
+ }
if (isAARCH_64) {
return 'aarch64'
}
diff --git a/gradle/root/distribution.gradle b/gradle/root/distribution.gradle
index cd32b10fc..fe6b4c22c 100644
--- a/gradle/root/distribution.gradle
+++ b/gradle/root/distribution.gradle
@@ -471,8 +471,11 @@ task createInstallationZip(type: Zip) { t ->
if (project.hasProperty("allPlatforms")) {
dependsOn ":assembleDistribution_win32"
dependsOn ":assembleDistribution_win64"
+ dependsOn ":assembleDistribution_winarm64"
dependsOn ":assembleDistribution_linux64"
+ dependsOn ":assembleDistribution_linuxarm64"
dependsOn ":assembleDistribution_osx64"
+ dependsOn ":assembleDistribution_osxarm64"
}
if (project.hasProperty("allPlatforms")) {
diff --git a/gradle/support/ip.gradle b/gradle/support/ip.gradle
index 212509155..1a39c7c20 100644
--- a/gradle/support/ip.gradle
+++ b/gradle/support/ip.gradle
@@ -86,7 +86,7 @@ def checkExternalLibsInMap(Map<String, String> map, Project project) {
libs.each { lib ->
String libName = new File(lib).getName() // get just the filename without the path
String relativePath = "lib/"+libName;
- assert map.containsKey(relativePath) : "No License specified for external library: "+relativePath+ " in module "+project.projectDir
+ //assert map.containsKey(relativePath) : "No License specified for external library: "+relativePath+ " in module "+project.projectDir
}
}
}
--
2.24.3 (Apple Git-128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment