On Wed, Aug 28, 2019 at 10:17:29PM -0400, Lawrence Teo wrote:
> On Tue, Aug 27, 2019 at 10:52:52AM -0000, Christian Weisgerber wrote:
> > On 2019-08-21, Stuart Henderson <s...@spacehopper.org> wrote:
> > 
> > >> > * If you build ghidra on a system where gcc/g++/libstdc++ are
> > >> >   available, it does indeed link something against libstdc++ and
> > >> >   port-lib-depends-check indicates WANTLIB+=stdc++.
> > >> > 
> > >> > * If you build ghidra on a system where gcc/g++/libstdc++ are NOT
> > >> >   available, it still builds fine, something is linked against
> > >> >   libc++/libc++abi/pthread and port-lib-depends-check consequently
> > >> >   indicates WANTLIB+=${COMPILER_LIBCXX}.
> > >
> > > Is this enough? Untested beyond "does it create the right symlink".
> > >
> > > --- Makefile      12 Jul 2019 20:49:02 -0000      1.4
> > > +++ Makefile      21 Aug 2019 08:21:22 -0000
> > > @@ -39,6 +39,7 @@ post-extract:
> > >           ${WRKSRC}/ghidraRun
> > >   @perl -pi -e 's,#!/bin/bash,#!${LOCALBASE}/bin/bash,' \
> > >           ${WRKSRC}/support/launch.sh
> > > + ln -s c++ ${WRKDIR}/bin/g++
> > 
> > This actually breaks the build:
> > 
> > > Task :Decompiler:compileDecompileOpenbsd64ExecutableDecompileCpp FAILED
> > 
> > FAILURE: Build failed with an exception.
> > 
> > * What went wrong:
> > Execution failed for task 
> > ':Decompiler:compileDecompileOpenbsd64ExecutableDecompileCpp'.
> > > java.lang.NullPointerException (no error message)
> 
> I have been testing and tinkering as well but haven't gotten very far.
> Using sthen's diff and passing --stacktrace to gradle I got this output:
[snip]
> 
> That looks like something related to Gradle, so I did some digging in
> the *.gradle files in the Ghidra source tree.  I believe the file that
> needs to be fixed is
> ghidra-9.0.4/ghidra-Ghidra_9.0.4_build/GPL/nativeBuildProperties.gradle
> but I haven't figured out exactly how yet.

I think I got it.  This new diff tells Gradle to build the demangler
with Clang, and I also made it print the compiler and linker
executables to confirm:

C++ compiler is [clang++]
Linker is [clang++]

The resulting demangler_gnu is linked with libc++:

nori$ ldd 
/usr/local/share/java/ghidra/GPL/DemanglerGnu/os/openbsd64/demangler_gnu
/usr/local/share/java/ghidra/GPL/DemanglerGnu/os/openbsd64/demangler_gnu:
        Start            End              Type  Open Ref GrpRef Name
        000005b4d7026000 000005b4d7056000 exe   2    0   0      
/usr/local/share/java/ghidra/GPL/DemanglerGnu/os/openbsd64/demangler_gnu
        000005b73bfaa000 000005b73c086000 rlib  0    1   0      
/usr/lib/libc++.so.3.0
        000005b7588a8000 000005b7588ea000 rlib  0    2   0      
/usr/lib/libc++abi.so.1.0
        000005b6e100b000 000005b6e1018000 rlib  0    1   0      
/usr/lib/libpthread.so.26.1
        000005b6d8f74000 000005b6d8fa3000 rlib  0    1   0      
/usr/lib/libm.so.10.1
        000005b75bb5c000 000005b75bc50000 rlib  0    1   0      
/usr/lib/libc.so.95.1
        000005b79c817000 000005b79c817000 ld.so 0    1   0      
/usr/libexec/ld.so

I added --stacktrace to gradle's command line for easier future
debugging.

Tests/feedback welcome!


Index: Makefile
===================================================================
RCS file: /cvs/ports/security/ghidra/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- Makefile    23 Jul 2019 02:52:58 -0000      1.6
+++ Makefile    30 Aug 2019 03:27:26 -0000
@@ -7,7 +7,7 @@ COMMENT =       software reverse engineering (
 
 VERSION =      9.0.4
 GHIDRA_DATE =  20190516
-REVISION =     2
+REVISION =     3
 
 GH_ACCOUNT =   NationalSecurityAgency
 GH_PROJECT =   ghidra
@@ -23,7 +23,7 @@ MAINTAINER =  Lawrence Teo <lteo@openbsd.
 # Apache v2
 PERMIT_PACKAGE =       Yes
 
-WANTLIB +=             c m stdc++
+WANTLIB +=             c m ${COMPILER_LIBCXX}
 
 MASTER_SITES0 =                ${HOMEPAGE}
 MASTER_SITES1 =                
https://sourceforge.net/projects/yajsw/files/yajsw/yajsw-stable-${YAJSW_VER}/
@@ -113,11 +113,13 @@ pre-build:
        cp ${DISTDIR}/yajsw-stable-${YAJSW_VER}.zip \
                ${WRKDIR}/ghidra.bin/Ghidra/Features/GhidraServer
        cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} gradle -g ${WRKDIR}/gradle \
-               --no-daemon --offline -I ${WRKDIR}/repos.gradle yajswDevUnpack
+               --no-daemon --offline --stacktrace -I ${WRKDIR}/repos.gradle \
+               yajswDevUnpack
 
 do-build:
        cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} gradle -g ${WRKDIR}/gradle \
-               --no-daemon --offline -I ${WRKDIR}/repos.gradle buildGhidra
+               --no-daemon --offline --stacktrace -I ${WRKDIR}/repos.gradle \
+               buildGhidra
 
 do-install:
        ${INSTALL_DATA_DIR} ${PREFIX}/share/java
Index: patches/patch-GPL_nativeBuildProperties_gradle
===================================================================
RCS file: 
/cvs/ports/security/ghidra/patches/patch-GPL_nativeBuildProperties_gradle,v
retrieving revision 1.1
diff -u -p -r1.1 patch-GPL_nativeBuildProperties_gradle
--- patches/patch-GPL_nativeBuildProperties_gradle      23 Jul 2019 02:09:20 
-0000      1.1
+++ patches/patch-GPL_nativeBuildProperties_gradle      30 Aug 2019 03:52:01 
-0000
@@ -2,10 +2,12 @@ $OpenBSD: patch-GPL_nativeBuildPropertie
 
 Adapted from https://github.com/NationalSecurityAgency/ghidra/pull/490
 
+Force use of Clang.
+
 Index: GPL/nativeBuildProperties.gradle
 --- GPL/nativeBuildProperties.gradle.orig
 +++ GPL/nativeBuildProperties.gradle
-@@ -75,6 +75,10 @@ model {
+@@ -75,7 +75,21 @@ model {
                        architecture 'x86_64'
                        operatingSystem 'osx'
                }
@@ -14,5 +16,16 @@ Index: GPL/nativeBuildProperties.gradle
 +                      operatingSystem 'openbsd'
 +              }
        }       
++
++      toolChains {
++              // Force use of Clang
++              clang(Clang) {
++                      eachPlatform { tools ->
++                              println "C++ compiler is 
[${tools.cppCompiler.executable}]"
++                              println "Linker is [${tools.linker.executable}]"
++                      }
++              }
++      }
  }
  
+ 
/*******************************************************************************************

Reply via email to