From 5b7031c42ad40d462f1652e4565efcca434a5f61 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 20 Mar 2025 13:05:28 +0100 Subject: rules CC defaults: Add DEBUGFLAGS and ADD_DEBUGFLAGS config vars If in debug mode - DEBUGFLAGS replaces any resulting CFLAGS and CXXFLAGS, and - ADD_DEBUGFLAGS is appended to the resulting debug compile flags. --- CC/RULES | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'CC/RULES') diff --git a/CC/RULES b/CC/RULES index 0f1b0ff..eddf0b7 100644 --- a/CC/RULES +++ b/CC/RULES @@ -14,10 +14,12 @@ , "CXXFLAGS" , "LDFLAGS" , "ARFLAGS" + , "DEBUGFLAGS" , "ADD_COMPILE_FLAGS" , "ADD_CFLAGS" , "ADD_CXXFLAGS" , "ADD_LDFLAGS" + , "ADD_DEBUGFLAGS" , "AR" , "PATH" , "SYSTEM_TOOLS" @@ -63,6 +65,11 @@ , "object files. If the \"ARFLAGS\" specified in the defaults target are" , "empty, the rules will use [\"cqs\"]." ] + , "DEBUGFLAGS": + [ "Flags to be used for the debug-stage for both C and C++, instead of" + , "the resulting CFLAGS and CXXFLAGS, respectively." + , "Specifying this field overwrites values from \"base\"." + ] , "ADD_COMPILE_FLAGS": [ "Additional compilation flags for C and C++. Specifying this field" , "extends values from \"base\" for both, \"CFLAGS\" and \"CXXFLAGS\"." @@ -79,6 +86,11 @@ [ "Additional linker flags for linking the final CC library. Specifying" , "this field extends values from \"base\"." ] + , "ADD_DEBUGFLAGS": + [ "Additional compilation flags for the debug-stage. Specifying this" + , "field extends values from \"base\" for both, \"CFLAGS\" and" + , "\"CXXFLAGS\"." + ] , "PATH": [ "Path for looking up the compilers. Individual paths are joined" , "with \":\". Specifying this field extends values from \"base\"." @@ -119,6 +131,7 @@ , ["CXXFLAGS", {"type": "FIELD", "name": "CXXFLAGS"}] , ["LDFLAGS", {"type": "FIELD", "name": "LDFLAGS"}] , ["ARFLAGS", {"type": "FIELD", "name": "ARFLAGS"}] + , ["DEBUGFLAGS", {"type": "FIELD", "name": "DEBUGFLAGS"}] , ["AR", {"type": "FIELD", "name": "AR"}] , ["PATH", {"type": "FIELD", "name": "PATH"}] , ["provider", "CC"] @@ -169,6 +182,14 @@ , "else": {"type": "CALL_EXPRESSION", "name": "base-provides-++"} } ] + , ["provider", "DEBUGFLAGS"] + , [ "DEBUGFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "DEBUGFLAGS"} + , "then": {"type": "var", "name": "DEBUGFLAGS"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides-++"} + } + ] , ["provider", "AR"] , [ "AR" , { "type": "if" @@ -308,6 +329,40 @@ ] } ] + , [ "CFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "DEBUG"} + , "then": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": {"type": "var", "name": "DEBUGFLAGS"} + , "then": {"type": "var", "name": "DEBUGFLAGS"} + , "else": {"type": "var", "name": "CFLAGS"} + } + , {"type": "FIELD", "name": "ADD_DEBUGFLAGS"} + ] + } + , "else": {"type": "var", "name": "CFLAGS"} + } + ] + , [ "CXXFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "DEBUG"} + , "then": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": {"type": "var", "name": "DEBUGFLAGS"} + , "then": {"type": "var", "name": "DEBUGFLAGS"} + , "else": {"type": "var", "name": "CXXFLAGS"} + } + , {"type": "FIELD", "name": "ADD_DEBUGFLAGS"} + ] + } + , "else": {"type": "var", "name": "CXXFLAGS"} + } + ] , ["deps-fieldnames", ["base", "deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , [ "compile-args" -- cgit v1.2.3 From 3e0d1255cdf428fb4b7d2381fb82f8db0a0e8bf3 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 20 Mar 2025 14:58:17 +0100 Subject: rules CC: Use the -g flag as fallback in debug mode... ...if no flags are otherwise configured (by toolchain or rule-specific configuration variables). --- CC/EXPRESSIONS | 28 ++++++++++++++++++++++++---- CC/RULES | 10 ++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'CC/RULES') diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index c52b209..2911c34 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -819,6 +819,7 @@ , "CXXFLAGS" , "ADD_CFLAGS" , "ADD_CXXFLAGS" + , "DEBUG" , "pure C" , "srcs" , "hdrs" @@ -1189,15 +1190,32 @@ , "CXXFLAGS" , "ADD_CFLAGS" , "ADD_CXXFLAGS" + , "DEBUG" , "pure C" , "defaults-transition" ] , "imports": {"flags-cc": "flags-cc", "flags-cxx": "flags-cxx"} , "expression": - { "type": "if" - , "cond": {"type": "var", "name": "pure C"} - , "then": {"type": "CALL_EXPRESSION", "name": "flags-cc"} - , "else": {"type": "CALL_EXPRESSION", "name": "flags-cxx"} + { "type": "let*" + , "bindings": + [ [ "flags" + , { "type": "if" + , "cond": {"type": "var", "name": "pure C"} + , "then": {"type": "CALL_EXPRESSION", "name": "flags-cc"} + , "else": {"type": "CALL_EXPRESSION", "name": "flags-cxx"} + } + ] + ] + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "flags"} + , "then": {"type": "var", "name": "flags"} + , "else": + { "type": "if" + , "cond": {"type": "var", "name": "DEBUG"} + , "then": ["-g"] + } + } } } , "lib artifact": @@ -1210,6 +1228,7 @@ , "ADD_CXXFLAGS" , "AR" , "ENV" + , "DEBUG" , "name" , "pure C" , "srcs" @@ -1590,6 +1609,7 @@ , "ADD_CFLAGS" , "ADD_CXXFLAGS" , "ENV" + , "DEBUG" , "name" , "pure C" , "srcs" diff --git a/CC/RULES b/CC/RULES index eddf0b7..c618467 100644 --- a/CC/RULES +++ b/CC/RULES @@ -552,7 +552,10 @@ , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] , "ENV": ["The environment for any action generated."] - , "DEBUG": ["Compute the debug-stage, needed for local debugging."] + , "DEBUG": + [ "Compute the debug-stage, needed for local debugging." + , "If no compile flags are otherwise configured, [\"-g\"] will be taken." + ] , "LINT": [ "Also provide nodes describing compile actions and header files;" , "those can be used by lint rules (doing also the config transition)" @@ -752,7 +755,10 @@ , "taken from the [\"CC\", \"defaults\"] target" ] , "ENV": ["The environment for any action generated."] - , "DEBUG": ["Compute the debug-stage, needed for local debugging."] + , "DEBUG": + [ "Compute the debug-stage, needed for local debugging." + , "If no compile flags are otherwise configured, [\"-g\"] will be taken." + ] , "LINT": [ "Also provide nodes describing compile actions and header files;" , "those can be used by lint rules (doing also the config transition)" -- cgit v1.2.3 From e5201ee251d11675c8fcbd686056ff08bea118b5 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 3 Apr 2025 12:05:06 +0200 Subject: rules CC: Make DEBUG variable a map It expects now the key 'USE_DEBUG_FISSION', which enables debug fission, but does not add any flags on its own. For this, the 'FISSION_CONFIG' key is expected with certain entries that provide the compile and/or link flags that configure debug fission. The flags are added only where needed, i.e., before running or storing the respective compile or link actions. --- CC/EXPRESSIONS | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- CC/RULES | 52 +++++++++++++++++-- 2 files changed, 205 insertions(+), 8 deletions(-) (limited to 'CC/RULES') diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 2911c34..572ba04 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -682,6 +682,141 @@ } } } +, "add-fission-compile-flags": + { "doc": ["Add debug fission flags, if enabled, to existing compile flags."] + , "vars": ["COMPILE_FLAGS", "DEBUG"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "fission-config" + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "USE_DEBUG_FISSION" + , "map": + { "type": "var" + , "name": "DEBUG" + , "default": {"type": "empty_map"} + } + } + , "then": + { "type": "assert_non_empty" + , "msg": + [ "Debug fission requires non-empty debug map FISSION_CONFIG field" + ] + , "$1": + { "type": "lookup" + , "key": "FISSION_CONFIG" + , "map": + { "type": "var" + , "name": "DEBUG" + , "default": {"type": "empty_map"} + } + } + } + , "else": {"type": "empty_map"} + } + ] + , [ "flags" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "COMPILE_FLAGS"} + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "USE_SPLIT_DWARF" + , "map": {"type": "var", "name": "fission-config"} + } + , "then": ["-gsplit-dwarf"] + } + , { "type": "let*" + , "bindings": + [ [ "version" + , { "type": "lookup" + , "key": "DWARF_VERSION" + , "map": {"type": "var", "name": "fission-config"} + } + ] + ] + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "version"} + , "then": + [ { "type": "join" + , "$1": ["-gdwarf-", {"type": "var", "name": "version"}] + } + ] + } + } + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "USE_DEBUG_TYPES_SECTION" + , "map": {"type": "var", "name": "fission-config"} + } + , "then": ["-fdebug-types-section"] + } + ] + } + ] + ] + , "body": {"type": "var", "name": "flags"} + } + } +, "add-fission-link-flags": + { "doc": ["Add debug fission flags, if enabled, to existing link flags."] + , "vars": ["LDFLAGS", "DEBUG"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "fission-config" + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "USE_DEBUG_FISSION" + , "map": + { "type": "var" + , "name": "DEBUG" + , "default": {"type": "empty_map"} + } + } + , "then": + { "type": "assert_non_empty" + , "msg": + [ "Debug fission requires non-empty debug map FISSION_CONFIG field" + ] + , "$1": + { "type": "lookup" + , "key": "FISSION_CONFIG" + , "map": + { "type": "var" + , "name": "DEBUG" + , "default": {"type": "empty_map"} + } + } + } + , "else": {"type": "empty_map"} + } + ] + , [ "flags" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "LDFLAGS"} + , { "type": "if" + , "cond": + { "type": "lookup" + , "key": "USE_GDB_INDEX" + , "map": {"type": "var", "name": "fission-config"} + } + , "then": ["-Wl,--gdb-index"] + } + ] + } + ] + ] + , "body": {"type": "var", "name": "flags"} + } + } , "objects": { "vars": [ "COMPILER" @@ -694,6 +829,7 @@ , "compile-deps" , "cflags-files" ] + , "imports": {"add-fission-compile-flags": "add-fission-compile-flags"} , "expression": { "type": "let*" , "bindings": @@ -721,6 +857,9 @@ ] } ] + , [ "compile flags" + , {"type": "CALL_EXPRESSION", "name": "add-fission-compile-flags"} + ] ] , "body": { "type": "map_union" @@ -782,7 +921,7 @@ { "type": "++" , "$1": [ [{"type": "var", "name": "COMPILER"}] - , {"type": "var", "name": "COMPILE_FLAGS"} + , {"type": "var", "name": "compile flags"} , ["-I", "work", "-isystem", "include"] , ["-c", {"type": "var", "name": "work src_name"}] , ["-o", {"type": "var", "name": "work out"}] @@ -839,6 +978,7 @@ , "default-NON_SYSTEM_TOOLS": "default-NON_SYSTEM_TOOLS" , "compiler": "compiler" , "flags": "flags" + , "add-fission-compile-flags": "add-fission-compile-flags" } , "expression": { "type": "let*" @@ -863,6 +1003,9 @@ ] } ] + , [ "compile flags" + , {"type": "CALL_EXPRESSION", "name": "add-fission-compile-flags"} + ] , [ "include tree" , { "type": "singleton_map" , "key": "include" @@ -959,7 +1102,7 @@ , { "type": "++" , "$1": [ [{"type": "var", "name": "COMPILER"}] - , {"type": "var", "name": "COMPILE_FLAGS"} + , {"type": "var", "name": "compile flags"} , [ "-I" , "work" , "-isystem" @@ -1029,7 +1172,7 @@ , { "type": "++" , "$1": [ [{"type": "var", "name": "COMPILER"}] - , {"type": "var", "name": "COMPILE_FLAGS"} + , {"type": "var", "name": "compile flags"} , ["-I", "work", "-isystem", "include"] , ["-c", {"type": "var", "name": "work src_name"}] , ["-o", {"type": "var", "name": "work out"}] @@ -1632,6 +1775,8 @@ , "default-LDFLAGS": "default-LDFLAGS" , "default-TOOLCHAIN": "default-TOOLCHAIN" , "default-NON_SYSTEM_TOOLS": "default-NON_SYSTEM_TOOLS" + , "add-fission-compile-flags": "add-fission-compile-flags" + , "add-fission-link-flags": "add-fission-link-flags" } , "expression": { "type": "let*" @@ -1697,6 +1842,12 @@ ] , ["hdrs", {"type": "empty_map"}] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] + , [ "compile flags" + , {"type": "CALL_EXPRESSION", "name": "add-fission-compile-flags"} + ] + , [ "ld flags" + , {"type": "CALL_EXPRESSION", "name": "add-fission-link-flags"} + ] , [ "link-args" , { "type": "nub_right" , "$1": @@ -1758,9 +1909,9 @@ , "-o" , {"type": "var", "name": "binpath"} ] - , {"type": "var", "name": "COMPILE_FLAGS"} + , {"type": "var", "name": "compile flags"} , {"type": "var", "name": "link-args"} - , {"type": "var", "name": "LDFLAGS"} + , {"type": "var", "name": "ld flags"} ] } ] diff --git a/CC/RULES b/CC/RULES index c618467..61834f9 100644 --- a/CC/RULES +++ b/CC/RULES @@ -104,7 +104,23 @@ , "HOST_ARCH": ["The architecture on which the build actions are carried out."] , "TARGET_ARCH": ["The architecture for which to build."] - , "DEBUG": ["Compute the debug-stage, needed for local debugging."] + , "DEBUG": + [ "Map configuring the debug-stage, needed for local debugging." + , "If non-empty, debug mode is enabled." + , "" + , "The key \"USE_DEBUG_FISSION\" expects a flag which enables the debug" + , "fission mode, but does not add any flags. Explicitly setting it to a" + , "false value is needed to enable regular debug mode." + , "The key \"FISSION_CONFIG\" expects a map configuring debug fission." + , " - subkey \"USE_SPLIT_DWARF\" expects a flag that, if true, adds the" + , "-gsplit-dwarf compile flag." + , " - subkey \"DWARF_VERSION\" expects a string that adds the" + , "-gdwarf- compile flag." + , " - subkey \"USE_GDB_INDEX\" expects a flag that, if true, adds the" + , "-Wl,--gdb-index linker flag." + , " - subkey \"USE_DEBUG_TYPES_SECTION\" expects a flag that, if true," + , "adds the -fdebug-types-section compile flag." + ] } , "imports": { "base-provides": "defaults-base-provides" @@ -553,7 +569,22 @@ ] , "ENV": ["The environment for any action generated."] , "DEBUG": - [ "Compute the debug-stage, needed for local debugging." + [ "Map configuring the debug-stage, needed for local debugging." + , "If non-empty, debug mode is enabled." + , "" + , "The key \"USE_DEBUG_FISSION\" expects a flag which enables the debug" + , "fission mode, but does not add any flags. Explicitly setting it to a" + , "false value is needed to enable regular debug mode." + , "The key \"FISSION_CONFIG\" expects a map configuring debug fission." + , " - subkey \"USE_SPLIT_DWARF\" expects a flag that, if true, adds the" + , "-gsplit-dwarf compile flag." + , " - subkey \"DWARF_VERSION\" expects a string that adds the" + , "-gdwarf- compile flag." + , " - subkey \"USE_GDB_INDEX\" expects a flag that, if true, adds the" + , "-Wl,--gdb-index linker flag." + , " - subkey \"USE_DEBUG_TYPES_SECTION\" expects a flag that, if true," + , "adds the -fdebug-types-section compile flag." + , "" , "If no compile flags are otherwise configured, [\"-g\"] will be taken." ] , "LINT": @@ -756,7 +787,22 @@ ] , "ENV": ["The environment for any action generated."] , "DEBUG": - [ "Compute the debug-stage, needed for local debugging." + [ "Map configuring the debug-stage, needed for local debugging." + , "If non-empty, debug mode is enabled." + , "" + , "The key \"USE_DEBUG_FISSION\" expects a flag which enables the debug" + , "fission mode, but does not add any flags. Explicitly setting it to a" + , "false value is needed to enable regular debug mode." + , "The key \"FISSION_CONFIG\" expects a map configuring debug fission." + , " - subkey \"USE_SPLIT_DWARF\" expects a flag that, if true, adds the" + , "-gsplit-dwarf compile flag." + , " - subkey \"DWARF_VERSION\" expects a string that adds the" + , "-gdwarf- compile flag." + , " - subkey \"USE_GDB_INDEX\" expects a flag that, if true, adds the" + , "-Wl,--gdb-index linker flag." + , " - subkey \"USE_DEBUG_TYPES_SECTION\" expects a flag that, if true," + , "adds the -fdebug-types-section compile flag." + , "" , "If no compile flags are otherwise configured, [\"-g\"] will be taken." ] , "LINT": -- cgit v1.2.3 From 95905ca12f6433916ba3c326685f3cdfd92ce89f Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 21 Mar 2025 13:44:59 +0100 Subject: rules CC: Add DWP configuration variable ...defining the DWARF format packaging tool to use once debug fission is supported. --- CC/RULES | 45 +++++++++++++++++++++++++++++++++++++++++++-- CC/TARGETS | 1 + 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'CC/RULES') diff --git a/CC/RULES b/CC/RULES index 61834f9..a6c775c 100644 --- a/CC/RULES +++ b/CC/RULES @@ -21,6 +21,7 @@ , "ADD_LDFLAGS" , "ADD_DEBUGFLAGS" , "AR" + , "DWP" , "PATH" , "SYSTEM_TOOLS" ] @@ -44,9 +45,13 @@ , "CC": ["The C compiler to use"] , "CXX": ["The C++ compiler to use"] , "AR": ["The archiver tool to use"] + , "DWP": + [ "The DWARF format packaging tool to use. Required by debug builds that" + , "enable debug fission." + ] , "SYSTEM_TOOLS": - [ "List of tools (\"CC\", \"CXX\", or \"AR\") that should be taken from" - , "the system instead of from \"toolchain\" (if specified)." + [ "List of tools (\"CC\", \"CXX\", \"AR\", or \"DWP\") that should be" + , "taken from the system instead of from \"toolchain\" (if specified)." ] , "CFLAGS": [ "Flags for C compilation. Specifying this field overwrites" @@ -149,6 +154,7 @@ , ["ARFLAGS", {"type": "FIELD", "name": "ARFLAGS"}] , ["DEBUGFLAGS", {"type": "FIELD", "name": "DEBUGFLAGS"}] , ["AR", {"type": "FIELD", "name": "AR"}] + , ["DWP", {"type": "FIELD", "name": "DWP"}] , ["PATH", {"type": "FIELD", "name": "PATH"}] , ["provider", "CC"] , [ "CC" @@ -214,6 +220,14 @@ , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } ] + , ["provider", "DWP"] + , [ "DWP" + , { "type": "if" + , "cond": {"type": "var", "name": "DWP"} + , "then": {"type": "var", "name": "DWP"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] , ["provider", "PATH"] , [ "PATH" , { "type": "nub_left" @@ -279,6 +293,20 @@ } ] } + , { "type": "if" + , "cond": {"type": "FIELD", "name": "DWP"} + , "then": + [ { "type": "singleton_map" + , "key": "DWP" + , "value": + { "type": "if" + , "cond": {"type": "FIELD", "name": "toolchain"} + , "then": true + , "else": false + } + } + ] + } , { "type": "foreach" , "range": {"type": "FIELD", "name": "SYSTEM_TOOLS"} , "var": "tool" @@ -432,6 +460,7 @@ , "CXXFLAGS" , "LDFLAGS" , "AR" + , "DWP" , "ARFLAGS" , "PATH" , "ENV" @@ -472,6 +501,7 @@ , "ADD_CFLAGS" , "ADD_CXXFLAGS" , "AR" + , "DWP" , "ENV" , "DEBUG" , "LINT" @@ -567,6 +597,11 @@ [ "The archive tool to used for creating the library" , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] + , "DWP": + [ "The DWARF format packaging tool to use in debug builds that enable" + , "debug fission." + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." + ] , "ENV": ["The environment for any action generated."] , "DEBUG": [ "Map configuring the debug-stage, needed for local debugging." @@ -726,6 +761,7 @@ , "CXXFLAGS" , "ADD_CFLAGS" , "ADD_CXXFLAGS" + , "DWP" , "ENV" , "DEBUG" , "LINT" @@ -785,6 +821,11 @@ [ "The flags to add to the default ones for CXX" , "taken from the [\"CC\", \"defaults\"] target" ] + , "DWP": + [ "The DWARF format packaging tool to use in debug builds that enable" + , "debug fission." + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." + ] , "ENV": ["The environment for any action generated."] , "DEBUG": [ "Map configuring the debug-stage, needed for local debugging." diff --git a/CC/TARGETS b/CC/TARGETS index 2da456b..f629f7e 100644 --- a/CC/TARGETS +++ b/CC/TARGETS @@ -5,6 +5,7 @@ , "CFLAGS": [] , "CXXFLAGS": [] , "AR": ["ar"] + , "DWP": ["dwp"] , "PATH": ["/bin", "/usr/bin"] } } -- cgit v1.2.3