From a8695a96d02e360f7068b6425764894b0ad4e734 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 14 Mar 2023 10:02:23 +0800 Subject: [PATCH] =?UTF-8?q?-=20enhancement:=20Options=20in=20compiler=20se?= =?UTF-8?q?t=20settings,=20to=20generate=20protection=20code=20for=20stack?= =?UTF-8?q?=20smashing=20attack.=20=EF=BC=88Enable=20for=20Debug=20setting?= =?UTF-8?q?s=20by=20default)=20=20=20-=20enhancement:=20Options=20in=20com?= =?UTF-8?q?piler=20set=20settings,=20to=20enable=20address=20sanitizer.=20?= =?UTF-8?q?Not=20available=20in=20windows.=EF=BC=88Enable=20for=20Debug=20?= =?UTF-8?q?settings=20by=20default)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.md | 4 +- RedPandaIDE/compiler/compilerinfo.cpp | 18 +++++- RedPandaIDE/compiler/compilerinfo.h | 2 + RedPandaIDE/settings.cpp | 11 ++-- RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 14 ++++- RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 60 ++++++++++++------- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 16 +++-- 7 files changed, 91 insertions(+), 34 deletions(-) diff --git a/NEWS.md b/NEWS.md index c660bf10..35151a6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/RedPandaIDE/compiler/compilerinfo.cpp b/RedPandaIDE/compiler/compilerinfo.cpp index a1a8fc14..98350d15 100644 --- a/RedPandaIDE/compiler/compilerinfo.cpp +++ b/RedPandaIDE/compiler/compilerinfo.cpp @@ -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("Normal"," ")); + sl.append(QPair("Strong","-strong")); + sl.append(QPair("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("Address","address")); + sl.append(QPair("Thread","thread")); + sl.append(QPair("Leak","leak")); + sl.append(QPair("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"); diff --git a/RedPandaIDE/compiler/compilerinfo.h b/RedPandaIDE/compiler/compilerinfo.h index 2ac68296..7827a2b4 100644 --- a/RedPandaIDE/compiler/compilerinfo.h +++ b/RedPandaIDE/compiler/compilerinfo.h @@ -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" diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 4dc14fba..eeb8d966 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -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 diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 7db3b581..e1f66fbd 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -6503,7 +6503,7 @@ Check ISO C/C++/C++0x conformance (-pedantic) - Verificar conformidade ISO C/C++/C++0x (-pedantic) + Verificar conformidade ISO C/C++/C++0x (-pedantic) Only check the code for syntax errors (-fsyntax-only) @@ -6717,6 +6717,18 @@ Lua files + + Check for stack smashing attacks (-fstack-protector) + + + + Check ISO C/C++ conformance (-pedantic) + + + + Enable Sanitizer (-fsanitize=) + + RegisterModel diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 2b4c1f95..a037ef31 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -762,7 +762,7 @@ p, li { white-space: pre-wrap; } Syntax error for objects larger than - 当变量占用栈空间大于此值时报错 + 当变量占用栈空间大于此值时报错 @@ -8537,7 +8537,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -8547,7 +8547,7 @@ Are you really want to continue? 生成性能分析信息(-pg) - + Warnings 代码警告 @@ -8566,42 +8566,60 @@ Are you really want to continue? C语言标准 (-std) - + Enable AddressSanitizer (-fsanitize=address) + 启用 + + + + Check for stack smashing attacks (-fstack-protector) + 检查栈溢出(stack smashing)错误 (-fstack-protector) + + + + Enable Sanitizer (-fsanitize=) + 启用地址消毒(-fsanitize=) + + + Inhibit all warning messages (-w) 忽略所有警告信息(-w) - + Show most warnings (-Wall) 启用常见问题警告(-Wall) - + Show some more warnings (-Wextra) 启用更多问题警告(-Wextra) - - Check ISO C/C++/C++0x conformance (-pedantic) - 检查ISO C/C++/C++0x语法一致性(-pedantic) + + Check ISO C/C++ conformance (-pedantic) + 检查是否严格遵守ISO C/C++标准 - + Check ISO C/C++/C++0x conformance (-pedantic) + 检查ISO C/C++/C++0x语法一致性(-pedantic) + + + Only check the code for syntax errors (-fsyntax-only) 只进行语法检查(不编译)(-fsyntax-only) - + Make all warnings into errors (-Werror) 将警告作为错误处理(-Werror) - + Abort compilation on first error (-Wfatal-errors) 遇到第一个错误后立即中止编译(-Wfatal-errors) - + Linker 链接器 @@ -8610,17 +8628,17 @@ Are you really want to continue? 链接Objective-C程序 (-lobjc) - + Do not use standard system libraries (-nostdlib) 不使用标准库和系统启动文件(-nostdlib) - + Do not create a console window (-mwindows) 不产生控制台窗口(-mwindows) - + Strip executable (-s) 剥除附加信息(-s) @@ -8641,7 +8659,7 @@ Are you really want to continue? 仅预处理(-E) - + Use pipes instead of temporary files during compilation (-pipe) 编译时使用管道而不是临时文件(-pipe) @@ -8650,7 +8668,7 @@ Are you really want to continue? 只生成汇编代码(-S) - + Confirm 确认 @@ -8671,13 +8689,13 @@ Are you really want to continue? 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index dffa1069..127c0c3a 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -6114,10 +6114,6 @@ Show some more warnings (-Wextra) - - Check ISO C/C++/C++0x conformance (-pedantic) - - Only check the code for syntax errors (-fsyntax-only) @@ -6282,6 +6278,18 @@ Lua files + + Check for stack smashing attacks (-fstack-protector) + + + + Check ISO C/C++ conformance (-pedantic) + + + + Enable Sanitizer (-fsanitize=) + + RegisterModel