Skip to content
2 changes: 2 additions & 0 deletions arch/_common_switches.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
##arch/_common_switches.sh: Switches sourced after defines.
##@copyright GPL-2.0+
if ((AB_FLAGS_ATOMIC)); then CFLAGS_COMMON+=('-latomic'); LDFLAGS_COMMON+=('-latomic'); fi
if ((AB_FLAGS_SSP)); then CFLAGS_COMMON+=('-fstack-protector-strong' '--param=ssp-buffer-size=4'); fi
if ((AB_FLAGS_SCP)); then CFLAGS_GCC_COMMON+=('-fstack-clash-protection'); fi
if ((AB_FLAGS_RRO)); then LDFLAGS_COMMON+=('-Wl,-z,relro'); fi
Expand All @@ -9,6 +10,7 @@ if ((AB_FLAGS_FTF)); then CPPFLAGS_COMMON+=('-U_FORTIFY_SOURCE' '-D_FORTIFY_SOUR
if ((AB_FLAGS_O3)); then CFLAGS_COMMON_OPTI="${CFLAGS_COMMON_OPTI/O2/O3}"; fi
if ((AB_FLAGS_OS)); then CFLAGS_COMMON_OPTI="${CFLAGS_COMMON_OPTI/O2/Os}"; fi
if ((AB_FLAGS_EXC)); then CFLAGS_COMMON+=('-fexceptions'); fi
if ((AB_FLAGS_Y2038)); then CPPFLAGS_COMMON+=('-D_FILE_OFFSET_BITS=64' '-D_TIME_BITS=64'); fi
# Only functions (via compiler and/or kernel, and hardware) on ...
#
# - amd64 (x86-64): Intel CET (compiler: -fcf-protection=full,
Expand Down
1 change: 1 addition & 0 deletions arch/armv4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LDFLAGS_COMMON_ARCH=('-Wl,--gc-sections')

CFLAGS_COMMON_ARCH+=('-march=armv4' '-mfloat-abi=soft')
CFLAGS_GCC_ARCH=('-mtune=strongarm110')
AB_FLAGS_Y2038=1
1 change: 1 addition & 0 deletions arch/armv6hf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LDFLAGS_COMMON_ARCH=('-Wl,--gc-sections')

CFLAGS_COMMON_ARCH+=('-march=armv6' '-mfloat-abi=hard')
CFLAGS_GCC_ARCH=('-mtune=arm1176jz-s')
AB_FLAGS_Y2038=1
1 change: 1 addition & 0 deletions arch/armv7hf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LDFLAGS_COMMON_ARCH=('-Wl,--gc-sections')

CFLAGS_COMMON_ARCH+=('-march=armv7-a' '-mfloat-abi=hard' '-mfpu=neon' '-mthumb')
CFLAGS_GCC_ARCH=('-mtune=cortex-a7')
AB_FLAGS_Y2038=1
3 changes: 2 additions & 1 deletion arch/i486.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
CFLAGS_COMMON_ARCH=('-O2' '-fno-tree-ch' '-ffunction-sections' '-fdata-sections' '-mno-omit-leaf-frame-pointer')
LDFLAGS_COMMON_ARCH=('-Wl,--gc-sections')

CPPFLAGS_COMMON_ARCH=('-D_TIME_BITS=64' '-D_FILE_OFFSET_BITS=64')
CFLAGS_COMMON_ARCH+=('-march=i486' '-mtune=generic')

RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=i486' '-Clink-args=-latomic')

AB_FLAGS_Y2038=1
1 change: 1 addition & 0 deletions arch/powerpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ CFLAGS_COMMON_ARCH+=('-m32' '-mcpu=603' '-mtune=G4' '-mno-altivec' '-msecure-plt
GOFLAGS=${GOFLAGS/-buildmode=pie/}

RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=603' '-Ctarget-feature=+hard-float,+secure-plt,-altivec')
AB_FLAGS_Y2038=1
9 changes: 9 additions & 0 deletions lib/default-defines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ ABINFOCOMPRESS=1
ABELFDEP=0 # Guess dependencies from ldd?
ABSTRIP=1 # Should ELF be stripped off debug and unneeded symbols?

# Add -latomic to compiler flags.
# Useful when dealing with architectures lacking 64-bit and longer atomic
# operations.
AB_FLAGS_ATOMIC=0

# Use -O3 instead?
AB_FLAGS_O3=0

Expand All @@ -59,6 +64,10 @@ AB_FLAGS_EXC=1
# Enable control flow integrity protection.
AB_FLAGS_CFP=1

# Enable Y2038 mitigations:
# -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
AB_FLAGS_Y2038=0

AB_SAN_ADD=0
AB_SAN_THR=0
AB_SAN_LEK=0
Expand Down
5 changes: 4 additions & 1 deletion native/abnativefunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ static int abdie(WORD_LIST *list) {
// cd "$SRCDIR"
const auto *srcdir_v = find_variable("SRCDIR");
if (srcdir_v && srcdir_v->value) {
chdir(srcdir_v->value);
if (chdir(srcdir_v->value) != 0) {
log->logException(fmt::format("Unable to chdir() to {0}: {1}",
srcdir_v->value, strerror(errno)));
}
}
log->logDiagnostic(diag);
log->logException(message ? message : std::string());
Expand Down
2 changes: 2 additions & 0 deletions sets/exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"filter_elf": ["ABSTRIP", "ABSPLITDBG", "SYMTAB"],
"flags": [
"AB_FLAGS_ATOMIC",
"AB_FLAGS_SSP",
"AB_FLAGS_SCP",
"AB_FLAGS_RRO",
Expand All @@ -39,6 +40,7 @@
"AB_FLAGS_CFP",
"AB_FLAGS_PIC",
"AB_FLAGS_PIE",
"AB_FLAGS_Y2038",
"AB_SAN_ADD",
"AB_SAN_THR",
"AB_SAN_LEK",
Expand Down
7 changes: 6 additions & 1 deletion templates/11-cmakeninja.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ build_cmakeninja_configure() {
fi
BUILD_START

# NOTE: CMake does not add ENV{CPPFLAGS} to
# CMAKE_${LANGUAGE}_FLAGS_INIT. We must either patch CMake or add
# CPPFLAGS to CFLAGS and CXXFLAGS manually.
export CFLAGS="$CPPFLAGS $CFLAGS"
export CXXFLAGS="$CPPFLAGS $CXXFLAGS"
abinfo "Running CMakeLists.txt to generate Ninja Configuration ..."
ab_tostringarray CMAKE_AFTER
ab_tostringarray CMAKE_AFTER
cmake "$SRCDIR" "${CMAKE_DEF[@]}" "${CMAKE_AFTER[@]}" -GNinja \
|| abdie "Failed to run CMakeLists.txt: $?."
}
Expand Down
9 changes: 7 additions & 2 deletions templates/12-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ build_cmake_configure() {
|| abdie "Failed to enter shadow build directory: $?."
fi

BUILD_START
BUILD_START

# NOTE: CMake does not add ENV{CPPFLAGS} to
# CMAKE_${LANGUAGE}_FLAGS_INIT. We must either patch CMake or add
# CPPFLAGS to CFLAGS and CXXFLAGS manually.
export CFLAGS="$CPPFLAGS $CFLAGS"
export CXXFLAGS="$CPPFLAGS $CXXFLAGS"
abinfo "Running CMakeLists.txt to generate Makefile ..."
ab_tostringarray CMAKE_AFTER
ab_tostringarray CMAKE_AFTER
cmake "$SRCDIR" "${CMAKE_DEF[@]}" "${CMAKE_AFTER[@]}" \
|| abdie "Failed to run CMakeLists.txt: $?."
}
Expand Down
Loading