Skip to content

Commit

Permalink
Scons: Cleanup how noelf and unstriped mode are handled
Browse files Browse the repository at this point in the history
* The "noelf" is now done in common code, making it have effect
  for onefile for Linux if bootstrap is used.

* The option name for unstriped was mispelled, corrected that.

* Moved setting of striped and unstriped symbols to common
  code.
  • Loading branch information
kayhayen committed Apr 4, 2022
1 parent f7584dc commit 53b5729
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"tshape",
"ucrt",
"uncompiled",
"unstripped",
"unstriped",
"virtualenv",
"vmprof",
"zstandard",
Expand Down
5 changes: 3 additions & 2 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15651,8 +15651,9 @@ Organisational
g++ and MinGW compilers, plus adequate errors messages are given, if
the compiler version is too low.

- There is now a ``--unstripped`` option that just keeps the debug
information in the file, but doesn't keep the assertions.
- There is now a ``--unstripped`` (since renamed to ``--unstriped``)
option that just keeps the debug information in the file, but doesn't
keep the assertions.

This will be helpful when looking at generated assembler code from
Nuitka to not have the distortions that ``--debug`` causes (reduced
Expand Down
4 changes: 2 additions & 2 deletions Developer_Manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1027,9 +1027,9 @@ processes:

Windows subsystem mode: Disable console for windows builds.

- ``unstripped_mode``
- ``unstriped_mode``

Unstripped mode: Do not remove debug symbols.
Unstriped mode: Do not remove debug symbols.

- ``clang_mode``

Expand Down
2 changes: 1 addition & 1 deletion UserPlugin-Creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ the methods have no argument.
+--------------------------------------+-----------------------------------------------------------------------------------+
| isStandaloneMode | *bool* = ``--standalone`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
| isUnstripped | *bool* = ``--unstripped`` or ``--profile`` |
| isUnstriped | *bool* = ``--unstriped`` or ``--profile`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
| isVerbose | *bool* = ``--verbose`` |
+--------------------------------------+-----------------------------------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion misc/run-valgrind.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
sys.executable,
nuitka_binary,
tempdir,
"--unstripped",
"--unstriped",
"--quiet",
os.environ.get("NUITKA_EXTRA_OPTIONS", ""),
input_file,
Expand Down
6 changes: 1 addition & 5 deletions nuitka/MainControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
from nuitka.utils.ModuleNames import ModuleName
from nuitka.utils.ReExecute import callExecProcess, reExecuteNuitka
from nuitka.utils.StaticLibraries import getSystemStaticLibPythonPath
from nuitka.utils.Utils import getArchitecture, getOS, isMacOS, isWin32Windows
from nuitka.utils.Utils import getArchitecture, isMacOS, isWin32Windows
from nuitka.Version import getCommercialVersion, getNuitkaVersion

from . import ModuleRegistry, Options, OutputDirectories, TreeXML
Expand Down Expand Up @@ -535,7 +535,6 @@ def runSconsBackend(quiet):
"nuitka_python": asBoolStr(isNuitkaPython()),
"debug_mode": asBoolStr(Options.is_debug),
"python_debug": asBoolStr(Options.isPythonDebug()),
"unstripped_mode": asBoolStr(Options.isUnstripped()),
"module_mode": asBoolStr(Options.shallMakeModule()),
"full_compat": asBoolStr(Options.is_fullcompat),
"experimental": ",".join(Options.getExperimentalIndications()),
Expand Down Expand Up @@ -606,9 +605,6 @@ def runSconsBackend(quiet):
len(ModuleRegistry.getUncompiledTechnicalModules())
)

if getOS() == "Windows":
options["noelf_mode"] = asBoolStr(True)

if Options.isProfile():
options["profile_mode"] = asBoolStr(True)

Expand Down
4 changes: 2 additions & 2 deletions nuitka/OptionParsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ def _getDataFileTagsOptionHelp():
)

debug_group.add_option(
"--unstripped",
"--unstriped",
action="store_true",
dest="unstripped",
dest="unstriped",
default=False,
help="""\
Keep debug info in the resulting object file for better debugger interaction.
Expand Down
10 changes: 5 additions & 5 deletions nuitka/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,17 +858,17 @@ def isPythonDebug():
return options.python_debug or sys.flags.debug


def isUnstripped():
""":returns: bool derived from ``--unstripped`` or ``--profile``
def isUnstriped():
""":returns: bool derived from ``--unstriped`` or ``--profile``
A binary is called stripped when debug information is not present, an
unstripped when it is present. For profiling and debugging it will be
unstriped when it is present. For profiling and debugging it will be
necessary, but it doesn't enable debug checks like ``--debug`` does.
Passed to Scons as ``unstripped_mode`` to it can ask the linker to
Passed to Scons as ``unstriped_mode`` to it can ask the linker to
include symbol information.
"""
return options.unstripped or options.profile
return options.unstriped or options.profile


def isProfile():
Expand Down
54 changes: 15 additions & 39 deletions nuitka/build/Backend.scons
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ from nuitka.Tracing import (
)
from nuitka.utils.Execution import check_output
from nuitka.utils.Json import loadJsonFromFilename
from nuitka.utils.Utils import isDebianBasedLinux, isNetBSD
from nuitka.utils.Utils import isDebianBasedLinux, isMacOS, isNetBSD

from .SconsCaching import enableCcache, enableClcache
from .SconsCompilerSettings import (
Expand All @@ -82,7 +82,6 @@ from .SconsUtils import (
getArgumentList,
getArgumentRequired,
getExecutablePath,
getMsvcVersion,
getMsvcVersionString,
initScons,
isGccName,
Expand Down Expand Up @@ -182,18 +181,17 @@ if static_libpython:
# no longer cross compile this way.
win_target = os.name == "nt"

# Non-elf binary, for linker settings.
noelf_mode = getArgumentBool("noelf_mode", False)

macosx_target = sys.platform == "darwin"

# Windows subsystem mode: Disable console for windows builds.
disable_console = getArgumentBool("disable_console", False)

# Windows might be running a Python whose DLL we have to use.
uninstalled_python = getArgumentBool("uninstalled_python", False)

# Unstripped mode: Do not remove debug symbols.
unstripped_mode = getArgumentBool("unstripped_mode", False)
# Unstriped mode: Do not remove debug symbols.
unstriped_mode = getArgumentBool("unstriped_mode", False)

# Target arch, uses for compiler choice and quick linking of constants binary
# data.
Expand Down Expand Up @@ -382,6 +380,8 @@ env.the_compiler = env["CC"]
env.the_cc_name = os.path.normcase(os.path.basename(env.the_compiler))
env.standalone_mode = standalone_mode
env.debug_mode = debug_mode
env.unstriped_mode = debug_mode or unstriped_mode
env.noelf_mode = noelf_mode
env.source_dir = source_dir
env.low_memory = low_memory
env.macos_min_version = macos_min_version
Expand Down Expand Up @@ -463,9 +463,6 @@ if env.gcc_mode and not env.clang_mode and env.gcc_version >= (8,):
]
)

if env.gcc_mode and not noelf_mode and not macosx_target:
env.Append(LINKFLAGS=["-z", "noexecstack"])

if env.msvc_mode:
# With Clang on Windows, there is also an linker to use.
env.Append(
Expand Down Expand Up @@ -789,8 +786,14 @@ elif not module_mode:
# For NetBSD the rpath is required, on FreeBSD it's warned as unused.
if isNetBSD():
env.Append(LINKFLAGS=["-rpath=" + python_lib_path])
elif macosx_target and module_mode:
env.Append(LINKFLAGS=["-undefined", "dynamic_lookup"])

if isMacOS():
if module_mode:
# Dynamic lookup needed for extension modules.
env.Append(LINKFLAGS=["-undefined", "dynamic_lookup"])
else:
# For macOS we need to make sure install_name_tool can do its work
env.Append(LINKFLAGS=["-headerpad_max_install_names"])

# The static include files reside in Nuitka installation, which may be where
# the "nuitka.build" package lives.
Expand All @@ -806,37 +809,13 @@ if not os.path.exists(os.path.join(nuitka_include, "nuitka", "prelude.h")):
# that is located inside Nuitka installation.
env.Append(CPPPATH=[source_dir, nuitka_include, os.path.join(nuitka_src, "static_src")])

if env.debug_mode or unstripped_mode:
# Use debug format, so we get good tracebacks from it.
if env.gcc_mode:
env.Append(LINKFLAGS=["-g"])
env.Append(CCFLAGS=["-g"])
env.Append(ASFLAGS=["-g"])

if not env.clang_mode:
env.Append(CCFLAGS=["-feliminate-unused-debug-types"])
elif env.msvc_mode:
env.Append(CCFLAGS=["/Z7"])

# Higher MSVC versions need this for parallel compilation
if job_count > 1 and getMsvcVersion(env) >= 11:
env.Append(CCFLAGS=["/FS"])

env.Append(LINKFLAGS=["/DEBUG"])
else:
if env.gcc_mode:
if macosx_target:
env.Append(LINKFLAGS=["-Wno-deprecated-declarations"])
elif not env.clang_mode:
env.Append(LINKFLAGS=["-s"])


# MinGW64 for 64 bits needs this due to CPython bugs.
if env.mingw_mode and target_arch == "x86_64":
env.Append(CPPDEFINES=["MS_WIN64"])

# Set load libpython from binary directory default
if env.gcc_mode and not macosx_target and not win_target and not module_mode:
if env.gcc_mode and not isMacOS() and not win_target and not module_mode:
if env.standalone_mode:
rpath = "$$ORIGIN"
else:
Expand All @@ -850,9 +829,6 @@ if env.gcc_mode and not macosx_target and not win_target and not module_mode:
if "linux" in sys.platform:
env.Append(LINKFLAGS=["-Wl,--disable-new-dtags"])

# For macOS we need to make sure install_name_tool can do its work
if macosx_target and not module_mode:
env.Append(LINKFLAGS=["-headerpad_max_install_names"])

addConstantBlobFile(
env=env,
Expand Down
34 changes: 10 additions & 24 deletions nuitka/build/Onefile.scons
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ from .SconsUtils import (
getArgumentList,
getArgumentRequired,
getExecutablePath,
getMsvcVersion,
getMsvcVersionString,
initScons,
isGccName,
Expand All @@ -82,6 +81,9 @@ from .SconsUtils import (
writeSconsReport,
)

# spell-checker: ignore ccversion,ccflags,werror,cppdefines,cpppath,cppflags
# spell-checker: ignore cxxflags,ldflags

# Set the arguments.
setArguments(ARGUMENTS)

Expand Down Expand Up @@ -132,11 +134,14 @@ lto_mode = getArgumentDefaulted("lto_mode", "auto")
# no longer cross compile this way.
win_target = os.name == "nt"

# Non-elf binary, for linker settings.
noelf_mode = getArgumentBool("noelf_mode", False)

# Windows subsystem mode: Disable console for windows builds.
disable_console = getArgumentBool("disable_console", False)

# Unstripped mode: Do not remove debug symbols.
unstripped_mode = getArgumentBool("unstripped_mode", False)
# Unstriped mode: Do not remove debug symbols.
unstriped_mode = getArgumentBool("unstriped_mode", False)

# Target arch, uses for compiler choice and quick linking of constants binary
# data.
Expand Down Expand Up @@ -298,6 +303,8 @@ env.the_compiler = env["CC"] or env["CXX"]
env.the_cc_name = os.path.normcase(os.path.basename(env.the_compiler))
env.standalone_mode = True # We are only used in this case.
env.debug_mode = debug_mode
env.unstriped_mode = debug_mode or unstriped_mode
env.noelf_mode = noelf_mode
env.source_dir = source_dir
env.low_memory = False # Never a concern in this case.
env.macos_min_version = macos_min_version
Expand Down Expand Up @@ -467,27 +474,6 @@ env.Append(
],
)

if debug_mode or unstripped_mode:
# Use debug format, so we get good tracebacks from it.
if env.gcc_mode:
env.Append(CCFLAGS=["-g"])
env.Append(ASFLAGS=["-g"])

if not env.clang_mode:
env.Append(CCFLAGS=["-feliminate-unused-debug-types"])
elif env.msvc_mode:
env.Append(CCFLAGS=["/Z7"])

# Higher MSVC versions need this for parallel compilation
if job_count > 1 and getMsvcVersion(env) >= 11:
env.Append(CCFLAGS=["/FS"])

env.Append(LINKFLAGS=["/DEBUG"])
else:
if env.gcc_mode:
if not env.clang_mode:
env.Append(LINKFLAGS=["-s"])

# Tell compiler to create a program.
if env.msvc_mode:
env.Append(CCFLAGS=["/MT"]) # Multithreaded, static version of C run time.
Expand Down
30 changes: 30 additions & 0 deletions nuitka/build/SconsCompilerSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ def setupCCompiler(env, lto_mode, pgo_mode, job_count):

env.Append(CPPDEFINES=["__NUITKA_NO_ASSERT__"])

_enableDebugSystemSettings(env, job_count=job_count)

if env.gcc_mode and not env.noelf_mode:
env.Append(LINKFLAGS=["-z", "noexecstack"])


def _enablePgoSettings(env, pgo_mode):
if pgo_mode == "no":
Expand Down Expand Up @@ -665,6 +670,31 @@ def _enablePgoSettings(env, pgo_mode):
env.pgo_mode = pgo_mode


def _enableDebugSystemSettings(env, job_count):
if env.unstriped_mode:
# Use debug format, so we get good tracebacks from it.
if env.gcc_mode:
env.Append(LINKFLAGS=["-g"])
env.Append(CCFLAGS=["-g"])

if not env.clang_mode:
env.Append(CCFLAGS=["-feliminate-unused-debug-types"])
elif env.msvc_mode:
env.Append(CCFLAGS=["/Z7"])

# Higher MSVC versions need this for parallel compilation
if job_count > 1 and getMsvcVersion(env) >= 11:
env.Append(CCFLAGS=["/FS"])

env.Append(LINKFLAGS=["/DEBUG"])
else:
if env.gcc_mode:
if isMacOS():
env.Append(LINKFLAGS=["-Wno-deprecated-declarations"])
elif not env.clang_mode:
env.Append(LINKFLAGS=["-s"])


def switchFromGccToGpp(env):
if not env.gcc_mode or env.clang_mode:
env.gcc_version = None
Expand Down
7 changes: 7 additions & 0 deletions nuitka/build/SconsInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
)
from nuitka.utils.InstalledPythons import findInstalledPython
from nuitka.utils.SharedLibraries import detectBinaryMinMacOS
from nuitka.utils.Utils import getOS, isMacOS

from .SconsCaching import checkCachingSuccess
from .SconsUtils import flushSconsReports
Expand Down Expand Up @@ -371,6 +372,12 @@ def setCommonOptions(options):
if Options.getLtoMode() != "auto":
options["lto_mode"] = Options.getLtoMode()

if getOS() == "Windows" or isMacOS():
options["noelf_mode"] = asBoolStr(True)

if Options.isUnstriped():
options["unstriped_mode"] = asBoolStr(True)

cpp_defines = Plugins.getPreprocessorSymbols()
if cpp_defines:
options["cpp_defines"] = ",".join(
Expand Down
1 change: 0 additions & 1 deletion nuitka/freezer/Onefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ def _runOnefileScons(quiet, onefile_compression):
"result_exe": OutputDirectories.getResultFullpath(onefile=True),
"source_dir": source_dir,
"debug_mode": asBoolStr(Options.is_debug),
"unstripped_mode": asBoolStr(Options.isUnstripped()),
"experimental": ",".join(Options.getExperimentalIndications()),
"trace_mode": asBoolStr(Options.shallTraceExecution()),
"target_arch": getArchitecture(),
Expand Down

0 comments on commit 53b5729

Please sign in to comment.