Skip to content
Snippets Groups Projects
Commit cb8b3401 authored by Alessandro Di Federico's avatar Alessandro Di Federico
Browse files

Enable `-no-pie` only if the compiler supports it

A previous commit introduced `-no-pie` to disable PIE in GCC versions
higher than 5.2. However, earlier versions don't support such an option.
This commit introduces the necessary detection mechanism to enable it or
not.
parent ef30e87a
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") ...@@ -71,6 +71,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
add_definitions("-D_FILE_OFFSET_BITS=64") add_definitions("-D_FILE_OFFSET_BITS=64")
include_directories(argparse/) include_directories(argparse/)
CHECK_CXX_COMPILER_FLAG("-no-pie" COMPILER_SUPPORTS_NO_PIE)
if(COMPILER_SUPPORTS_NO_PIE)
set(NO_PIE "${TEST_CFLAGS} -no-pie")
endif()
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
add_executable(revamb ptcdump.cpp main.cpp debughelper.cpp variablemanager.cpp add_executable(revamb ptcdump.cpp main.cpp debughelper.cpp variablemanager.cpp
......
...@@ -12,7 +12,7 @@ find_program(DIFF diff) ...@@ -12,7 +12,7 @@ find_program(DIFF diff)
# * A cross compiler (provided by the user) # * A cross compiler (provided by the user)
# * libtinycode-${ARCH}.so, which must be in the search path # * libtinycode-${ARCH}.so, which must be in the search path
set(SUPPORTED_ARCHITECTURES "aarch64;alpha;arm;armeb;cris;i386;m68k;microblaze;microblazeel;mips;mips64;mips64el;mipsel;mipsn32;mipsn32el;nbd;or32;ppc;ppc64;ppc64abi32;s390x;sh4;sh4eb;sparc;sparc32plus;sparc64;unicore32;x86_64") set(SUPPORTED_ARCHITECTURES "aarch64;alpha;arm;armeb;cris;m68k;microblaze;microblazeel;mips;mips64;mips64el;mipsel;mipsn32;mipsn32el;nbd;or32;ppc;ppc64;ppc64abi32;s390x;sh4;sh4eb;sparc;sparc32plus;sparc64;unicore32;x86_64")
set(QEMU_BIN_PATH "${QEMU_INSTALL_PATH}/bin") set(QEMU_BIN_PATH "${QEMU_INSTALL_PATH}/bin")
set(QEMU_LIB_PATH "${QEMU_INSTALL_PATH}/lib") set(QEMU_LIB_PATH "${QEMU_INSTALL_PATH}/lib")
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Test definitions # Test definitions
set(SRC ${CMAKE_SOURCE_DIR}/tests/Runtime) set(SRC ${CMAKE_SOURCE_DIR}/tests/Runtime)
set(TEST_CFLAGS "-std=c99 -static -fno-pic -fno-pie -g") set(TEST_CFLAGS "-std=c99 -static -fno-pic -fno-pie ${NO_PIE} -g")
set(TESTS "calc" "function_call" "floating_point" "syscall" "global") set(TESTS "calc" "function_call" "floating_point" "syscall" "global")
## calc ## calc
...@@ -89,7 +89,7 @@ foreach(ARCH ${SUPPORTED_ARCHITECTURES}) ...@@ -89,7 +89,7 @@ foreach(ARCH ${SUPPORTED_ARCHITECTURES})
# Compose the command line to link support.c and the translated binaries # Compose the command line to link support.c and the translated binaries
string(REPLACE "-" "_" NORMALIZED_ARCH "${ARCH}") string(REPLACE "-" "_" NORMALIZED_ARCH "${ARCH}")
compile_executable("$(${CMAKE_BINARY_DIR}/li-csv-to-ld-options ${BINARY}.ll.li.csv) ${BINARY}${CMAKE_C_OUTPUT_EXTENSION} ${CMAKE_BINARY_DIR}/support.c -DTARGET_${NORMALIZED_ARCH} -lz -lm -lrt -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -g -fno-pie -no-pie" compile_executable("$(${CMAKE_BINARY_DIR}/li-csv-to-ld-options ${BINARY}.ll.li.csv) ${BINARY}${CMAKE_C_OUTPUT_EXTENSION} ${CMAKE_BINARY_DIR}/support.c -DTARGET_${NORMALIZED_ARCH} -lz -lm -lrt -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -g -fno-pie ${NO_PIE}"
"${BINARY}.translated" "${BINARY}.translated"
COMPILE_TRANSLATED) COMPILE_TRANSLATED)
......
...@@ -126,8 +126,14 @@ elif [ "$OPTIMIZE" -eq 2 ]; then ...@@ -126,8 +126,14 @@ elif [ "$OPTIMIZE" -eq 2 ]; then
"$LLC" -O2 -filetype=obj "$LL_OPT" -o "$OBJ" -regalloc=fast -disable-machine-licm "$LLC" -O2 -filetype=obj "$LL_OPT" -o "$OBJ" -regalloc=fast -disable-machine-licm
fi fi
if "$CC" -no-pie |& grep 'unrecognized command line option'; then
DISABLE_PIE="-fno-pie"
else
DISABLE_PIE="-fno-pie -no-pie"
fi
"$CC" $("$TOOPT" "$CSV") \ "$CC" $("$TOOPT" "$CSV") \
"$OBJ" \ "$OBJ" \
-lz -lm -lrt \ -lz -lm -lrt \
-o "$OUTPUT" \ -o "$OUTPUT" \
-fno-pie -no-pie $DISABLE_PIE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment