Blackberry mkspecs: Refine compiler options
authorPeter Hartmann <phartmann@rim.com>
Thu, 20 Sep 2012 12:11:25 +0000 (14:11 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 1 Oct 2012 08:22:06 +0000 (10:22 +0200)
stack-protector-strong gives performance benefits over
stack-protector-all and is still checking more than -stack-protector,
so seems to be a good middle way and we want to use it when it is
there.

The -shared option for the compiler (not the linker) prevents a
RIM internal version of qcc from forcing -fPIE, and should not harm
in general when set.

In addition, add a method "compilerSupportsFlag" for Windows as is
present in the Unix configure script.

Change-Id: Iba300e9cb82f34043e7b36f8e45287a1aed2a1a5
Original-patch-by: Greg Bentz
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
configure
mkspecs/blackberry-armv7le-qcc/qmake.conf
mkspecs/blackberry-x86-qcc/qmake.conf
mkspecs/common/qcc-base.conf
tools/configure/configureapp.cpp
tools/configure/configureapp.h

index 58d7a86..19eef3f 100755 (executable)
--- a/configure
+++ b/configure
@@ -230,9 +230,9 @@ compilerSupportsFlag()
     cat >conftest.cpp <<EOF
 int main() { return 0; }
 EOF
-    "$TEST_COMPILER" "$@" -o conftest.o conftest.cpp
+    $TEST_COMPILER "$@" -o conftest-out.o conftest.cpp
     ret=$?
-    rm -f conftest.cpp conftest.o
+    rm -f conftest.cpp conftest-out.o
     return $ret
 }
 
@@ -783,6 +783,7 @@ CFG_V8SNAPSHOT=auto
 CFG_QML_DEBUG=yes
 CFG_JAVASCRIPTCORE_JIT=auto
 CFG_PKGCONFIG=auto
+CFG_STACK_PROTECTOR_STRONG=auto
 
 # Target architecture
 CFG_ARCH=
@@ -2660,6 +2661,17 @@ if [ "$CFG_REDUCE_EXPORTS" != "no" ]; then
     fi
 fi
 
+# auto-detect -fstack-protector-strong support (for QNX only currently)
+if [ "$XPLATFORM_QNX" = "yes" ]; then
+    if compilerSupportsFlag -fstack-protector-strong; then
+       CFG_STACK_PROTECTOR_STRONG=yes
+    else
+       CFG_STACK_PROTECTOR_STRONG=no
+    fi
+else
+   CFG_STACK_PROTECTOR_STRONG=no
+fi
+
 # detect the availability of the -Bsymbolic-functions linker optimization
 if [ "$CFG_REDUCE_RELOCATIONS" != "no" ]; then
     if "$unixtests/bsymbolic_functions.test" "$TEST_COMPILER" "$OPT_VERBOSE"; then
@@ -5296,6 +5308,7 @@ if [ "$CFG_USE_GNUMAKE" = "yes" ]; then
     QMAKE_CONFIG="$QMAKE_CONFIG GNUmake"
 fi
 [ "$CFG_REDUCE_EXPORTS" = "yes" ] && QT_CONFIG="$QT_CONFIG reduce_exports"
+[ "$CFG_STACK_PROTECTOR_STRONG" = "yes" ] && QT_CONFIG="$QT_CONFIG stack-protector-strong"
 [ "$CFG_REDUCE_RELOCATIONS" = "yes" ] && QT_CONFIG="$QT_CONFIG reduce_relocations"
 [ "$CFG_STRIP" = "no" ] && QMAKE_CONFIG="$QMAKE_CONFIG nostrip"
 [ "$CFG_PRECOMPILE" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG precompile_header"
index 4a8cde7..2886527 100644 (file)
@@ -2,11 +2,17 @@
 # qmake configuration for blackberry armv7le systems
 #
 
+load(qt_config)
+
 DEFINES += Q_OS_BLACKBERRY
 CONFIG += blackberry
 LIBS += -lbps
 
 # Blackberry also has support for stack smashing protection in its libc
-QMAKE_CFLAGS += -fstack-protector -fstack-protector-all
+contains(QT_CONFIG, stack-protector-strong) {
+    QMAKE_CFLAGS += -fstack-protector-strong
+} else {
+    QMAKE_CFLAGS += -fstack-protector -fstack-protector-all
+}
 
 include(../common/qcc-base-qnx-armv7le.conf)
index 24bbffe..4dc3da6 100644 (file)
@@ -2,11 +2,17 @@
 # qmake configuration for blackberry x86 systems
 #
 
+load(qt_config)
+
 DEFINES += Q_OS_BLACKBERRY
 CONFIG += blackberry
 LIBS += -lbps
 
 # Blackberry also has support for stack smashing protection in its libc
-QMAKE_CFLAGS += -fstack-protector -fstack-protector-all
+contains(QT_CONFIG, stack-protector-strong) {
+    QMAKE_CFLAGS += -fstack-protector-strong
+} else {
+    QMAKE_CFLAGS += -fstack-protector -fstack-protector-all
+}
 
 include(../common/qcc-base-qnx-x86.conf)
index b6abb8f..76d3d13 100644 (file)
@@ -17,7 +17,7 @@ QMAKE_CFLAGS_WARN_ON        += -Wall -W
 QMAKE_CFLAGS_WARN_OFF       += -w
 QMAKE_CFLAGS_RELEASE        += -O2
 QMAKE_CFLAGS_DEBUG          += -g
-QMAKE_CFLAGS_SHLIB          += -fPIC
+QMAKE_CFLAGS_SHLIB          += -fPIC -shared
 QMAKE_CFLAGS_STATIC_LIB     += -fPIC
 QMAKE_CFLAGS_APP            += -fPIE
 QMAKE_CFLAGS_YACC           += -Wno-unused -Wno-parentheses
index 4fce6f2..d1244f0 100644 (file)
@@ -1504,6 +1504,8 @@ void Configure::applySpecSpecifics()
         dictionary[ "QT_ICONV" ]            = "no";
 
         dictionary["DECORATIONS"]           = "default windows styled";
+    } else if ((platform() == QNX) || (platform() == BLACKBERRY)) {
+        dictionary["STACK_PROTECTOR_STRONG"] = "auto";
     }
 }
 
@@ -2041,6 +2043,8 @@ bool Configure::checkAvailability(const QString &part)
         available = tryCompileProject("unix/iconv") || tryCompileProject("unix/gnu-libiconv");
     } else if (part == "CUPS") {
         available = (platform() != WINDOWS) && (platform() != WINDOWS_CE) && tryCompileProject("unix/cups");
+    } else if (part == "STACK_PROTECTOR_STRONG") {
+        available = (platform() == QNX || platform() == BLACKBERRY) && compilerSupportsFlag("qcc -fstack-protector-strong");
     }
 
     return available;
@@ -2153,6 +2157,10 @@ void Configure::autoDetection()
     if (dictionary["QT_CUPS"] == "auto")
         dictionary["QT_CUPS"] = checkAvailability("CUPS") ? "yes" : "no";
 
+    // Detection of -fstack-protector-strong support
+    if (dictionary["STACK_PROTECTOR_STRONG"] == "auto")
+        dictionary["STACK_PROTECTOR_STRONG"] = checkAvailability("STACK_PROTECTOR_STRONG") ? "yes" : "no";
+
     // Mark all unknown "auto" to the default value..
     for (QMap<QString,QString>::iterator i = dictionary.begin(); i != dictionary.end(); ++i) {
         if (i.value() == "auto")
@@ -2511,6 +2519,9 @@ void Configure::generateOutputVars()
     if (dictionary["QT_GLIB"] == "yes")
         qtConfig += "glib";
 
+    if (dictionary["STACK_PROTECTOR_STRONG"] == "yes")
+        qtConfig += "stack-protector-strong";
+
     // We currently have no switch for QtConcurrent, so add it unconditionally.
     qtConfig += "concurrent";
 
@@ -2872,6 +2883,27 @@ bool Configure::tryCompileProject(const QString &projectPath, const QString &ext
     return code == 0;
 }
 
+bool Configure::compilerSupportsFlag(const QString &compilerAndArgs)
+{
+    QFile file("conftest.cpp");
+    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+        cout << "could not open temp file for writing" << endl;
+        return false;
+    }
+    if (!file.write("int main() { return 0; }\r\n")) {
+        cout << "could not write to temp file" << endl;
+        return false;
+    }
+    file.close();
+    // compilerAndArgs contains compiler because there is no way to query it
+    QString command = compilerAndArgs + " -o conftest-out.o conftest.cpp";
+    int code = 0;
+    QString output = Environment::execute(command, &code);
+    file.remove();
+    QFile::remove("conftest-out.o");
+    return code == 0;
+}
+
 void Configure::generateQConfigPri()
 {
     // Generate qconfig.pri
index 3261f4f..8cae9da 100644 (file)
@@ -175,6 +175,7 @@ private:
 #endif
 
     bool tryCompileProject(const QString &projectPath, const QString &extraOptions = QString());
+    bool compilerSupportsFlag(const QString &compilerAndArgs);
 
     void desc(const char *description, int startingAt = 0, int wrapIndent = 0);
     void desc(const char *option, const char *description, bool skipIndent = false, char fillChar = '.');