Skip to content

Commit

Permalink
preverify is built from source (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
orenskl authored Nov 23, 2024
1 parent 5df4dfb commit 17c6d2c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (${TARGET} STREQUAL PICO)
include(pico_sdk_import.cmake)
endif()

project(pjvm VERSION 0.0.4)
project(pjvm VERSION 0.0.6)

include(CTest)

Expand Down Expand Up @@ -116,7 +116,7 @@ if (${TARGET} STREQUAL PICO)
DESTINATION .
RENAME pjvm-${PROJECT_VERSION}.uf2
)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/tools/wrapjar.sh ${CMAKE_SOURCE_DIR}/lib/tools/preverify/bin/preverify
install(PROGRAMS ${CMAKE_SOURCE_DIR}/tools/wrapjar.sh ${BINARY_DIR}/preverify-prefix/src/preverify-build/preverify
DESTINATION bin
)
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc
Expand Down
30 changes: 26 additions & 4 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ include(ExternalProject)

project(jvm)

#
# Build the host utilities that are used to build the classes library
#

#
# Build ROMGEN, this is actually the VM but its built to generate a
# ROM image of the classes library
#
ExternalProject_Add(romgen SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/romgen
CMAKE_ARGS -DROMGEN_VERSION=${LIBJVM_VERSION}
-DCMAKE_BUILD_TYPE:STRING=Release
Expand All @@ -19,6 +27,20 @@ ExternalProject_Add(romgen SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/romgen
INSTALL_COMMAND cmake -E echo "Skipping install step."
)
ExternalProject_Get_property(romgen BINARY_DIR)
set(ROMGEN_BINARY_DIR ${BINARY_DIR})

#
# Build PREVERIFY to transform the classes before running on the target
#
ExternalProject_Add(preverify SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/preverify
CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=Release
USES_TERMINAL_BUILD TRUE
BUILD_ALWAYS TRUE
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/preverify-prefix/src/preverify-build/preverify
INSTALL_COMMAND cmake -E echo "Skipping install step."
)
ExternalProject_Get_property(preverify BINARY_DIR)
set(PREVERIFY_BINARY_DIR ${BINARY_DIR})

if (${TARGET} STREQUAL PICO)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
Expand Down Expand Up @@ -136,15 +158,15 @@ set(JVM_CLASSES
)

add_custom_command(OUTPUT ROMImage.cpp
DEPENDS ${JVM_CLASSES} ${BINARY_DIR}/romgen
DEPENDS ${JVM_CLASSES} ${ROMGEN_BINARY_DIR}/romgen
COMMAND rm ARGS -rf ${CMAKE_BINARY_DIR}/classes ${CMAKE_BINARY_DIR}/classes.preverify
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/classes
COMMAND javac ARGS -source 1.4 -target 1.4 -d ${CMAKE_BINARY_DIR}/classes -bootclasspath ${CMAKE_BINARY_DIR}/classes ${JVM_CLASSES}
COMMAND ${CMAKE_SOURCE_DIR}/tools/preverify/bin/preverify ARGS -d ${CMAKE_BINARY_DIR}/classes.preverify ${CMAKE_BINARY_DIR}/classes
COMMAND ${PREVERIFY_BINARY_DIR}/preverify ARGS -d ${CMAKE_BINARY_DIR}/classes.preverify ${CMAKE_BINARY_DIR}/classes
COMMAND cd ARGS ${CMAKE_BINARY_DIR}/classes.preverify
COMMAND jar ARGS -cfM0 ${CMAKE_BINARY_DIR}/classes.jar .
COMMAND cd ARGS ${CMAKE_BINARY_DIR}
COMMAND ${BINARY_DIR}/romgen
COMMAND ${ROMGEN_BINARY_DIR}/romgen
-cp ${CMAKE_BINARY_DIR}/classes.jar
+RewriteROMConstantPool
+EnableAllROMOptimizations
Expand All @@ -154,7 +176,7 @@ add_custom_command(OUTPUT ROMImage.cpp
-romincludepath ${CMAKE_SOURCE_DIR}/src/vm
-romize
)
add_custom_target(classes ALL DEPENDS ROMImage.cpp romgen)
add_custom_target(classes ALL DEPENDS ROMImage.cpp romgen preverify)

if (${TARGET} STREQUAL PICO)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/doc
Expand Down
4 changes: 3 additions & 1 deletion lib/tools/preverify/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ add_executable(preverify

target_compile_definitions(preverify PRIVATE UNIX JAVAVERIFY TRIMMED ARCH=i386)
target_include_directories(preverify PRIVATE src)
target_compile_options(preverify PRIVATE)
target_compile_options(preverify PRIVATE -m32 -Werror)
target_link_options(preverify PRIVATE -m32)

Binary file removed lib/tools/preverify/bin/preverify
Binary file not shown.
5 changes: 5 additions & 0 deletions lib/tools/preverify/src/check_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

/*=========================================================================
* SYSTEM: Verifier
Expand All @@ -37,6 +40,8 @@
* Include files
*=======================================================================*/

#include <arpa/inet.h>

#include <check_code.h>

#include <opcodes.length>
Expand Down
8 changes: 6 additions & 2 deletions lib/tools/preverify/src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

/*=========================================================================
* SYSTEM: Verifier
* SUBSYSTEM: Operations on class files.
Expand Down Expand Up @@ -608,7 +612,7 @@ void
WriteClass(ClassClass *cb)
{
int fd;
char fname[1024];
char fname[BUFSIZ + 1024];
char buff[BUFSIZ];
char *nativeName = &buff[0];

Expand Down Expand Up @@ -725,7 +729,7 @@ WriteClass(ClassClass *cb)
}

tmpDirExists = TRUE; /* tmpDir exists with verified classes */
write(fd, class_buf, class_index);
size_t rv = write(fd, class_buf, class_index);
close(fd);
free(class_buf);
class_buf_size = 0;
Expand Down
11 changes: 8 additions & 3 deletions lib/tools/preverify/src/jar_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

/*=========================================================================
* SYSTEM: Verifier
* SUBSYSTEM: JAR support routines for the verifier.
Expand All @@ -44,6 +48,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>

#include <sys_api.h>
#include <path_md.h>
Expand Down Expand Up @@ -495,7 +500,7 @@ loadJARfile(zip_t *entry, const char* filename)
if (compLen != decompLen) {
return NULL;
}
fread(decompData, sizeof(char), decompLen, file);
size_t rv = fread(decompData, sizeof(char), decompLen, file);
break;

case DEFLATED: {
Expand Down Expand Up @@ -681,7 +686,7 @@ ReadFromZip(zip_t *entry)
jdstream = NULL;
goto done;
}
fread(decompData, sizeof(char), decompLen, file);
size_t rv = fread(decompData, sizeof(char), decompLen, file);
break;

case DEFLATED: {
Expand Down Expand Up @@ -790,7 +795,7 @@ ReadFromZip(zip_t *entry)
"Writing file [%s]...\n", sfname);

/* write the file to the tmpdir just created */
write(fd, decompData, decompLen);
size_t rv = write(fd, decompData, decompLen);

/* check for the JAR Manifest.mf file */

Expand Down
9 changes: 5 additions & 4 deletions lib/tools/preverify/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

/*=========================================================================
* SYSTEM: Verifier
* SUBSYSTEM: main program
Expand Down Expand Up @@ -52,8 +56,6 @@
* Globals and extern declarations
*=======================================================================*/

char str_buffer[STRINGBUFFERSIZE]; /* shared string buffer */

int processedfile = 0;
int errorCode = 0; /* Error code returned by program */

Expand Down Expand Up @@ -232,8 +234,7 @@ static void ProcessInputs(char *argname)
* argv: arg value(s)
* returns: nothing
*=======================================================================*/
int main(argc, argv)
register char **argv;
int main(int argc, char ** argv)
{
char *progname;
char *argv0 = argv[0];
Expand Down
11 changes: 5 additions & 6 deletions lib/tools/preverify/src/typedefs_md.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

#ifndef _TYPES_MD_H_
#define _TYPES_MD_H_

Expand Down Expand Up @@ -52,12 +56,7 @@ typedef long int32_t;
#endif /* SOLARIS2 */

#ifdef __linux__
#ifndef _UINT64_T
#define _UINT64_T
typedef unsigned long long uint64_t;
#define _UINT32_T
typedef unsigned long uint32_t;
#endif
#include <stdint.h>
#endif /* __linux__ */

#ifdef DARWIN
Expand Down

0 comments on commit 17c6d2c

Please sign in to comment.