Fix ACR+CMake builds using pregenerated bison/flex files

Changes inspired by the latest commits in the rz-ghidra repo
This commit is contained in:
pancake committed 2021-01-16 01:09:53 +01:00
1 parent 7e26a20ef2
commit c042d27534
7 files changed
+70 -49

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ option(BUILD_DECOMPILE_EXECUTABLE "Build \"decompile\" executable as used by Ghi
option(BUILD_DECOMPILE_CLI_EXECUTABLE "Build REPL decompiler (not needed for r2)" OFF)
option(BUILD_SLASPECS "Build Sleigh specs for architectures from Ghidra" ON)
option(BUILD_SLEIGH_PLUGIN "Build asm and anal plugin to use sleigh as a disassembler in r2" ON)
option(GENERATE_PARSERS "Re-generate all parsers with Bison/Flex instead of using pre-generated ones" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Vendored
+5 -5
View File
@@ -108,12 +108,12 @@ done
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
PKGNAME='r2ghidra' ; VERSION='5.0.0' ; VERSION_MAJOR=5; VERSION_MINOR=0; VERSION_PATCH=0; VERSION_NUMBER=50000; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
PKGNAME='r2ghidra' ; VERSION='5.0.1' ; VERSION_MAJOR=5; VERSION_MINOR=0; VERSION_PATCH=1; VERSION_NUMBER=50001; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
}
show_usage() {
cat <<EOF2
'configure' configures r2ghidra-5.0.0 to adapt to many kinds of systems.
'configure' configures r2ghidra-5.0.1 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
@@ -184,10 +184,10 @@ ocho() {
show_version() {
if [ "$QUIET" = 1 ]; then
echo "5.0.0"
echo "5.0.1"
exit 0
fi
echo "r2ghidra-5.0.0 configuration script done with acr v1.9.8.
echo "r2ghidra-5.0.1 configuration script done with acr v1.9.8.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
@@ -216,7 +216,7 @@ case $flag in
show_version ; ;;
-r|--r|--report)
echo "PKGNAME: r2ghidra"
echo "VERSION: 5.0.0"
echo "VERSION: 5.0.1"
echo "LANGS: c++"
echo "PKG-CONFIG: r_core"
exit 0
+1 -1
View File
@@ -1,5 +1,5 @@
PKGNAME r2ghidra
VERSION 5.0.0
VERSION 5.0.1
CONTACT pancake ; [email protected]
LANG_CXX!
+47 -32
View File
@@ -144,40 +144,55 @@ prepend_src_dir(DECOMPILER_SOURCE_CONSOLE_CXX)
prepend_src_dir(SLEIGH_COMPILER_SOURCE_CXX)
set(SOURCE "${DECOMPILER_SOURCE_BASE_CXX}")
find_package(BISON REQUIRED)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bison")
find_package(FLEX REQUIRED)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/flex")
if(GENERATE_PARSERS)
find_package(BISON REQUIRED)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bison")
find_package(FLEX REQUIRED)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/flex")
# build yacc files and append the output files to OUT_VAR
macro(build_bison OUT_VAR)
foreach(yacc_file ${ARGN})
get_filename_component(yacc_name "${yacc_file}" NAME_WE)
if("${yacc_name}" STREQUAL "slghparse")
set(yacc_prefix yy)
else()
set(yacc_prefix "${yacc_name}")
endif()
if(BISON_VERSION VERSION_LESS 2.6)
set(BISON_COMPILE_FLAGS "--name-prefix=${yacc_prefix}")
else()
set(BISON_COMPILE_FLAGS "-Dapi.prefix={${yacc_prefix}}")
endif()
BISON_TARGET(${yacc_name}
"${CMAKE_CURRENT_SOURCE_DIR}/${DECOMPILER_SOURCE_DIR}/${yacc_file}"
"${CMAKE_CURRENT_BINARY_DIR}/bison/${yacc_name}.cpp"
COMPILE_FLAGS ${BISON_COMPILE_FLAGS})
list(APPEND ${OUT_VAR} "${BISON_${yacc_name}_OUTPUTS}")
endforeach()
endmacro()
# build yacc files and append the output files to OUT_VAR
macro(build_bison OUT_VAR)
foreach(yacc_file ${ARGN})
get_filename_component(yacc_name "${yacc_file}" NAME_WE)
if("${yacc_name}" STREQUAL "slghparse")
set(yacc_prefix yy)
else()
set(yacc_prefix "${yacc_name}")
endif()
if(BISON_VERSION VERSION_LESS 2.6)
set(BISON_COMPILE_FLAGS "--name-prefix=${yacc_prefix}")
else()
set(BISON_COMPILE_FLAGS "-Dapi.prefix={${yacc_prefix}}")
endif()
BISON_TARGET(${yacc_name}
"${CMAKE_CURRENT_SOURCE_DIR}/${DECOMPILER_SOURCE_DIR}/${yacc_file}"
"${CMAKE_CURRENT_BINARY_DIR}/bison/${yacc_name}.cpp"
COMPILE_FLAGS ${BISON_COMPILE_FLAGS})
list(APPEND ${OUT_VAR} "${BISON_${yacc_name}_OUTPUTS}")
endforeach()
endmacro()
build_bison(SOURCE ${DECOMPILER_SOURCE_BASE_YACC})
build_bison(DECOMPILER_SOURCE_SLEIGH_CXX ${DECOMPILER_SOURCE_SLEIGH_YACC})
build_bison(SLEIGH_COMPILER_SOURCE_CXX ${SLEIGH_COMPILER_SOURCE_YACC})
build_bison(SOURCE ${DECOMPILER_SOURCE_BASE_YACC})
build_bison(DECOMPILER_SOURCE_SLEIGH_CXX ${DECOMPILER_SOURCE_SLEIGH_YACC})
build_bison(SLEIGH_COMPILER_SOURCE_CXX ${SLEIGH_COMPILER_SOURCE_YACC})
FLEX_TARGET(slghscan "${DECOMPILER_SOURCE_DIR}/${SLEIGH_COMPILER_SOURCE_FLEX}" "${CMAKE_CURRENT_BINARY_DIR}/flex/slghscan.cpp")
list(APPEND SLEIGH_COMPILER_SOURCE_CXX "${CMAKE_CURRENT_BINARY_DIR}/flex/slghscan.cpp")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/flex/slghparse.tab.hh" "#include \"../bison/slghparse.hpp\"")
FLEX_TARGET(slghscan "${DECOMPILER_SOURCE_DIR}/${SLEIGH_COMPILER_SOURCE_FLEX}" "${CMAKE_CURRENT_BINARY_DIR}/flex/slghscan.cpp")
list(APPEND SLEIGH_COMPILER_SOURCE_CXX "${CMAKE_CURRENT_BINARY_DIR}/flex/slghscan.cpp")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/flex/slghparse.tab.hh" "#include \"../bison/slghparse.hpp\"")
else()
list(APPEND SOURCE
"${DECOMPILER_SOURCE_DIR}/xml.hh"
"${DECOMPILER_SOURCE_DIR}/xml.cc")
list(APPEND DECOMPILER_SOURCE_SLEIGH_CXX
"${DECOMPILER_SOURCE_DIR}/pcodeparse.hh"
"${DECOMPILER_SOURCE_DIR}/pcodeparse.cc"
"${DECOMPILER_SOURCE_DIR}/grammar.hh"
"${DECOMPILER_SOURCE_DIR}/grammar.cc")
list(APPEND SLEIGH_COMPILER_SOURCE_CXX
"${DECOMPILER_SOURCE_DIR}/slghparse.hh"
"${DECOMPILER_SOURCE_DIR}/slghparse.cc"
"${DECOMPILER_SOURCE_DIR}/slghscan.cc")
endif()
add_library(ghidra_decompiler_base STATIC ${SOURCE})
target_include_directories(ghidra_decompiler_base PUBLIC "${DECOMPILER_SOURCE_DIR}")
@@ -236,4 +251,4 @@ if(BUILD_SLASPECS)
else()
unset(SLEIGHHOME_DEFAULT)
endif()
set(SLEIGHHOME_DEFAULT "${SLEIGHHOME_DEFAULT}" PARENT_SCOPE)
set(SLEIGHHOME_DEFAULT "${SLEIGHHOME_DEFAULT}" PARENT_SCOPE)
+10 -5
View File
@@ -52,12 +52,9 @@ G_DECOMPILER+=pcodecompile.cc
## G_DECOMPILER+=callgraph.cc
## G_DECOMPILER+=raw_arch.cc
G_DECOMPILER+= xml.cc ## bison
G_DECOMPILER+= pcodeparse.cc ## bison
# G_DECOMPILER+= slghparse.cc ## bison
# G_DECOMPILER+= grammar.cc ## bison
# G_DECOMPILER+= ruleparse.cc ## bison
USE_BISON=0
ifeq ($(USE_BISON),1)
$(GHIDRA_DECOMPILER)/grammar.cc: $(GHIDRA_DECOMPILER)/grammar.y
$(BISON) -p grammar -o $(GHIDRA_DECOMPILER)/grammar.cc $(GHIDRA_DECOMPILER)/grammar.y
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(GHIDRA_DECOMPILER)/grammar.o -c $(GHIDRA_DECOMPILER)/grammar.cc
@@ -78,6 +75,14 @@ $(GHIDRA_DECOMPILER)/slghparse.cc: $(GHIDRA_DECOMPILER)/slghparse.y
echo '#include \"slghparse.hpp\"' > $(GHIDRA_DECOMPILER)/slghparse.tab.hpp
$(BISON) -d -o $(GHIDRA_DECOMPILER)/slghparse.tab.hh $(GHIDRA_DECOMPILER)/slghparse.y
$(BISON) -o $(GHIDRA_DECOMPILER)/slghparse.cc $(GHIDRA_DECOMPILER)/slghparse.y
else
G_DECOMPILER+= grammar.cc
G_DECOMPILER+= ruleparse.cc
G_DECOMPILER+= xml.cc
G_DECOMPILER+= pcodeparse.cc
# G_DECOMPILER+= slghparse.cc ## bison
# G_DECOMPILER+= pcodeparse.cc ## bison
endif
.PHONY: $(GHIDRA_DECOMPILER)/slghparse.cc
.PHONY: $(GHIDRA_DECOMPILER)/slghscan.cc
+4 -4
View File
@@ -125,13 +125,13 @@ Datatype *R2TypeFactory::queryR2Typedef(const string &n, std::set<std::string> &
RCoreLock core(arch->getCore());
Sdb *sdb = core->anal->sdb_types;
const char *target = sdb_const_get(sdb, ("typedef." + n).c_str(), nullptr);
if(!target)
if(!target) {
return nullptr;
}
Datatype *resolved = fromCString(target, nullptr, &stackTypes);
if(!resolved)
if(!resolved) {
return nullptr;
}
Datatype *typedefd = resolved->clone();
setName(typedefd, n); // this removes the old name from the nametree
setName(resolved, resolved->getName()); // add the old name back
+2 -2
View File
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2019 - thestr4ng3r */
/* radare - LGPL - Copyright 2019-2021 - thestr4ng3r */
#include "R2Architecture.h"
#include "CodeXMLParse.h"
@@ -619,7 +619,7 @@ static int r2ghidra_fini(void *user, const char *cmd)
RCorePlugin r_core_plugin_ghidra = {
/* .name = */ "r2ghidra",
/* .desc = */ "Ghidra integration",
/* .desc = */ "Ghidra decompiler with pdg command",
/* .license = */ "GPL3",
/* .author = */ "thestr4ng3r",
/* .version = */ nullptr,