Skip to content

Commit

Permalink
have configure check/add -ffunction-sections and -fdata-sections
Browse files Browse the repository at this point in the history
based on patch by Denys Vlasenko. the original intent for using these
options was to enable linking optimizations. these are immediately
available for static linking applications to libc.a, and will also be
used for linking libc.so in a subsequent commit.

in addition to the original motives, this change works around a whole
class of toolchain bugs where the compiler generates relative address
expressions using a weak symbol and the assembler "optimizes out" the
relocation which should result by using the weak definition. (see gas
pr 18561 and gcc pr 66609, 68178, etc. for examples.) by having
different functions and data objects in their own sections, all
relative address expressions are cross-section and thus cannot be
resolved to constants until link time. this allows us to retain
support for affected compiler/assembler versions without invasive
and fragile source-level workarounds.
  • Loading branch information
richfelker committed Nov 4, 2015
1 parent 2f1d1f1 commit 27c1ecc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ fi
tryflag CFLAGS_AUTO -fno-unwind-tables
tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables

#
# Attempt to put each function and each data object in its own
# section. This both allows additional size optimizations at link
# time and works around a dangerous class of compiler/assembler bugs
# whereby relative address expressions are constant-folded by the
# assembler even when one or more of the symbols involved is
# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc.
#
tryflag CFLAGS_AUTO -ffunction-sections
tryflag CFLAGS_AUTO -fdata-sections

#
# On x86, make sure we don't have incompatible instruction set
# extensions enabled by default. This is bad for making static binaries.
Expand Down

0 comments on commit 27c1ecc

Please sign in to comment.