- enhancement: Options in compiler set settings, to generate protection code for stack smashing attack. (Enable for Debug settings by default)

- enhancement: Options in compiler set settings, to enable address sanitizer. Not available in windows.(Enable for Debug settings by default)
This commit is contained in:
Roy Qu 2023-03-14 10:02:23 +08:00
parent 99ca9796b1
commit a8695a96d0
7 changed files with 91 additions and 34 deletions

View File

@ -8,7 +8,9 @@ Red Panda C++ Version 2.18
- enhancement: Warn user and stop compile if project has missing files.
- enhancement: Warn user when exit and save settings failed.
- change: Remove compiler set options that's rarely used.
- enhancement: Options in compiler set settings, to generate syntax error for large stack objects.
- enhancement: Options in compiler set settings, to generate syntax error for large stack objects. Enable for Debug settings by default)
- enhancement: Options in compiler set settings, to generate protection code for stack smashing attack. Enable for Debug settings by default)
- enhancement: Options in compiler set settings, to enable address sanitizer. Not available in windows.Enable for Debug settings by default)
Red Panda C++ Version 2.17

View File

@ -151,17 +151,29 @@ void CompilerInfo::prepareCompilerOptions()
addOption(CC_CMD_OPT_DEBUG_INFO, QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3");
addOption(CC_CMD_OPT_PROFILE_INFO, QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg");
addOption(CC_CMD_OPT_SYNTAX_ONLY, QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only");
// Warnings
groupName = QObject::tr("Warnings");
addOption(CC_CMD_OPT_INHIBIT_ALL_WARNING, QObject::tr("Inhibit all warning messages (-w)"), groupName, true, true, false, "-w");
addOption(CC_CMD_OPT_WARNING_ALL,QObject::tr("Show most warnings (-Wall)"), groupName, true, true, false, "-Wall");
addOption(CC_CMD_OPT_WARNING_EXTRA,QObject::tr("Show some more warnings (-Wextra)"), groupName, true, true, false, "-Wextra");
addOption(CC_CMD_OPT_CHECK_ISO_CONFORMANCE, QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)"), groupName, true, true, false, "-pedantic");
addOption(CC_CMD_OPT_SYNTAX_ONLY, QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only");
addOption(CC_CMD_OPT_CHECK_ISO_CONFORMANCE, QObject::tr("Check ISO C/C++ conformance (-pedantic)"), groupName, true, true, false, "-pedantic");
addOption(CC_CMD_OPT_WARNING_AS_ERROR, QObject::tr("Make all warnings into errors (-Werror)"), groupName, true, true, false, "-Werror");
addOption(CC_CMD_OPT_ABORT_ON_ERROR , QObject::tr("Abort compilation on first error (-Wfatal-errors)"), groupName, true, true, false, "-Wfatal-errors");
sl.clear();
sl.append(QPair<QString,QString>("Normal"," "));
sl.append(QPair<QString,QString>("Strong","-strong"));
sl.append(QPair<QString,QString>("All","-all"));
addOption(CC_CMD_OPT_STACK_PROTECTOR , QObject::tr("Check for stack smashing attacks (-fstack-protector)"), groupName, false, false, true, "-fstack-protector",sl);
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
sl.clear();
sl.append(QPair<QString,QString>("Address","address"));
sl.append(QPair<QString,QString>("Thread","thread"));
sl.append(QPair<QString,QString>("Leak","leak"));
sl.append(QPair<QString,QString>("Undefined","undefined"));
addOption(CC_CMD_OPT_ADDRESS_SANITIZER , QObject::tr("Enable Sanitizer (-fsanitize=)"), groupName, true, true, true, "-fsanitize=",sl);
#endif
// Output
//groupName = QObject::tr("Output");

View File

@ -37,6 +37,8 @@
#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console"
#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe"
#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info"
#define CC_CMD_OPT_ADDRESS_SANITIZER "cc_cmd_opt_address_sanitizer"
#define CC_CMD_OPT_STACK_PROTECTOR "cc_cmd_opt_stack_protector"
#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm"
#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code"

View File

@ -2768,12 +2768,15 @@ static void setDebugOptions(Settings::PCompilerSet pSet, bool enableAsan = false
pSet->setCompileOption(CC_CMD_OPT_WARNING_ALL, COMPILER_OPTION_ON);
//pSet->setCompileOption(CC_CMD_OPT_WARNING_EXTRA, COMPILER_OPTION_ON);
pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, COMPILER_OPTION_ON);
if (enableAsan) {
pSet->setCustomCompileParams("-fsanitize=address");
pSet->setUseCustomCompileParams(true);
pSet->setCustomLinkParams("-fsanitize=address");
pSet->setUseCustomLinkParams(true);
pSet->setCompileOption(CC_CMD_OPT_ADDRESS_SANITIZER, "address");
// pSet->setCustomCompileParams("-fsanitize=address");
// pSet->setUseCustomCompileParams(true);
// pSet->setCustomLinkParams("-fsanitize=address");
// pSet->setUseCustomLinkParams(true);
}
pSet->setCompileOption(CC_CMD_OPT_STACK_PROTECTOR, "-strong");
pSet->setStaticLink(false);
pSet->setMaxObjectSize(2); //default stack size of gcc is 2MB

View File

@ -6503,7 +6503,7 @@
</message>
<message>
<source>Check ISO C/C++/C++0x conformance (-pedantic)</source>
<translation>Verificar conformidade ISO C/C++/C++0x (-pedantic)</translation>
<translation type="vanished">Verificar conformidade ISO C/C++/C++0x (-pedantic)</translation>
</message>
<message>
<source>Only check the code for syntax errors (-fsyntax-only)</source>
@ -6717,6 +6717,18 @@
<source>Lua files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check for stack smashing attacks (-fstack-protector)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check ISO C/C++ conformance (-pedantic)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable Sanitizer (-fsanitize=)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RegisterModel</name>

View File

@ -762,7 +762,7 @@ p, li { white-space: pre-wrap; }
<message>
<location filename="../settingsdialog/compilersetoptionwidget.ui" line="192"/>
<source>Syntax error for objects larger than</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/compilersetoptionwidget.ui" line="322"/>
@ -8537,7 +8537,7 @@ Are you really want to continue?</oldsource>
<translation>(-g3)</translation>
</message>
<message>
<location filename="../settings.cpp" line="2990"/>
<location filename="../settings.cpp" line="2992"/>
<source>Would you like Red Panda C++ to search for compilers in PATH?</source>
<translation>C++PATH路径中寻找gcc编译器吗</translation>
</message>
@ -8547,7 +8547,7 @@ Are you really want to continue?</oldsource>
<translation>(-pg)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="156"/>
<location filename="../compiler/compilerinfo.cpp" line="165"/>
<source>Warnings</source>
<translation></translation>
</message>
@ -8566,42 +8566,60 @@ Are you really want to continue?</oldsource>
<translation>C语言标准 (-std)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="157"/>
<source>Enable AddressSanitizer (-fsanitize=address)</source>
<translation type="obsolete"></translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="154"/>
<source>Check for stack smashing attacks (-fstack-protector)</source>
<translation>(stack smashing) (-fstack-protector)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="161"/>
<source>Enable Sanitizer (-fsanitize=)</source>
<translation>(-fsanitize=)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="166"/>
<source>Inhibit all warning messages (-w)</source>
<translation>(-w)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="158"/>
<location filename="../compiler/compilerinfo.cpp" line="167"/>
<source>Show most warnings (-Wall)</source>
<translation>(-Wall)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="159"/>
<location filename="../compiler/compilerinfo.cpp" line="168"/>
<source>Show some more warnings (-Wextra)</source>
<translation>(-Wextra)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="160"/>
<source>Check ISO C/C++/C++0x conformance (-pedantic)</source>
<translation>ISO C/C++/C++0x(-pedantic)</translation>
<location filename="../compiler/compilerinfo.cpp" line="169"/>
<source>Check ISO C/C++ conformance (-pedantic)</source>
<translation>ISO C/C++</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="161"/>
<source>Check ISO C/C++/C++0x conformance (-pedantic)</source>
<translation type="vanished">ISO C/C++/C++0x(-pedantic)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="170"/>
<source>Only check the code for syntax errors (-fsyntax-only)</source>
<translation>(-fsyntax-only)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="162"/>
<location filename="../compiler/compilerinfo.cpp" line="171"/>
<source>Make all warnings into errors (-Werror)</source>
<translation>(-Werror)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="163"/>
<location filename="../compiler/compilerinfo.cpp" line="172"/>
<source>Abort compilation on first error (-Wfatal-errors)</source>
<translation>(-Wfatal-errors)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="173"/>
<location filename="../compiler/compilerinfo.cpp" line="182"/>
<source>Linker</source>
<translation></translation>
</message>
@ -8610,17 +8628,17 @@ Are you really want to continue?</oldsource>
<translation type="vanished">Objective-C程序 (-lobjc)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="176"/>
<location filename="../compiler/compilerinfo.cpp" line="185"/>
<source>Do not use standard system libraries (-nostdlib)</source>
<translation>使(-nostdlib)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="177"/>
<location filename="../compiler/compilerinfo.cpp" line="186"/>
<source>Do not create a console window (-mwindows)</source>
<translation>(-mwindows)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="178"/>
<location filename="../compiler/compilerinfo.cpp" line="187"/>
<source>Strip executable (-s)</source>
<translation>(-s)</translation>
</message>
@ -8641,7 +8659,7 @@ Are you really want to continue?</oldsource>
<translation type="vanished">-E)</translation>
</message>
<message>
<location filename="../compiler/compilerinfo.cpp" line="174"/>
<location filename="../compiler/compilerinfo.cpp" line="183"/>
<source>Use pipes instead of temporary files during compilation (-pipe)</source>
<translation>使(-pipe)</translation>
</message>
@ -8650,7 +8668,7 @@ Are you really want to continue?</oldsource>
<translation type="vanished">(-S)</translation>
</message>
<message>
<location filename="../settings.cpp" line="2992"/>
<location filename="../settings.cpp" line="2994"/>
<source>Confirm</source>
<translation></translation>
</message>
@ -8671,13 +8689,13 @@ Are you really want to continue?</oldsource>
<translation type="vanished">&lt;br /&gt;&lt;br /&gt;</translation>
</message>
<message>
<location filename="../settings.cpp" line="2982"/>
<location filename="../settings.cpp" line="2988"/>
<location filename="../settings.cpp" line="2984"/>
<location filename="../settings.cpp" line="2990"/>
<source>Compiler set not configuared.</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="2984"/>
<location filename="../settings.cpp" line="2986"/>
<source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source>
<translation>C++&lt;br /&gt;%1&lt;br /&gt;%2</translation>
</message>

View File

@ -6114,10 +6114,6 @@
<source>Show some more warnings (-Wextra)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check ISO C/C++/C++0x conformance (-pedantic)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Only check the code for syntax errors (-fsyntax-only)</source>
<translation type="unfinished"></translation>
@ -6282,6 +6278,18 @@
<source>Lua files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check for stack smashing attacks (-fstack-protector)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Check ISO C/C++ conformance (-pedantic)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable Sanitizer (-fsanitize=)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RegisterModel</name>