Skip to content

Commit

Permalink
Document and work around GCC bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dlu-ch committed Jun 4, 2022
1 parent 6a9891a commit ec86b44
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/dlb_contrib/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# GCC: <https://gcc.gnu.org/>
# GNU Binutils: <https://www.gnu.org/software/binutils/>
# Tested with: gcc 8.3.0
# Tested with: gcc 10.2.1
# Executable: 'gcc'
# Executable: 'g++'
#
Expand Down Expand Up @@ -38,6 +39,23 @@
# linked_file=output_directory / 'application'
# ).start()

# About the effect of command line argument -o:
#
# In contrast to the specified behaviour, GCC does *not* always write its output to *file* as specified
# by '-o' *file*.
#
# At least for versions 2.8.0 to 12.1.0, the actual behaviour depends on a lot of factors:
# - target-platform dependent value of object-like preprecessor macros TARGET_OBJECT_SUFFIX, TARGET_EXECUTABLE_SUFFIX
# - presence of '.' in the last path component of *file*
# - presence of suffix '.o' in last path component of *file*
# - presence of command line options -c, -S, and -E (for some versions)
# - existence of *file* (for some versions)
#
# See OPT_o and convert_filename() in gcc/gcc.c[c] in <git://gcc.gnu.org/git/gcc.git>.
#
# If *file* has a suffix that is different from '.o', all these implicit path modifications (bugs)
# are ineffective on all platforms for the mentioned GCC versions.

__all__ = [
'Path', 'ObjectOrArchivePath',
'CCompilerGcc', 'CplusplusCompilerGcc',
Expand Down Expand Up @@ -163,7 +181,9 @@ async def redo(self, result, context):
# compile
compile_arguments = self.get_all_compile_arguments()
for source_file, optional_object_file in zip(result.source_files, optional_object_files):
with context.temporary() as make_rules_file, context.temporary() as temp_object_file:

# see "About the effect of command line argument -o" above
with context.temporary(suffix='.t') as make_rules_file, context.temporary(suffix='.t') as temp_object_file:
await context.execute_helper(
self.EXECUTABLE,
compile_arguments + [
Expand Down Expand Up @@ -259,7 +279,7 @@ async def redo(self, result, context):
link_arguments += self.get_subprogram_link_arguments(context)

# link
with context.temporary() as linked_file:
with context.temporary(suffix='.t') as linked_file: # see "About the effect of command line argument -o" above
link_arguments += [
'-o', linked_file,
*result.object_and_archive_files # note: type detection by suffix of path cannot be disabled
Expand Down

0 comments on commit ec86b44

Please sign in to comment.