* Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"?
@ 2023-03-19 12:38 3119369616.qq
2023-03-19 13:18 ` Arsen Arsenović
2023-03-19 18:15 ` David Brown
0 siblings, 2 replies; 3+ messages in thread
From: 3119369616.qq @ 2023-03-19 12:38 UTC (permalink / raw)
To: gcc
[-- Attachment #1: Type: text/plain, Size: 355 bytes --]
To divide functions into sections and then remove unused sections, I must provide flags "-fdata-sections" and "-ffunction-sections" in GCC and a flag "--gc-sections" in LD. Most of the build systems don't support these flags so GCC will generate bigger binaries.
Is it possible to enable this feature without giving any command line flags manually?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"?
2023-03-19 12:38 Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"? 3119369616.qq
@ 2023-03-19 13:18 ` Arsen Arsenović
2023-03-19 18:15 ` David Brown
1 sibling, 0 replies; 3+ messages in thread
From: Arsen Arsenović @ 2023-03-19 13:18 UTC (permalink / raw)
To: 3119369616.qq; +Cc: gcc
[-- Attachment #1: Type: text/plain, Size: 862 bytes --]
"3119369616.qq via Gcc" <gcc@gcc.gnu.org> writes:
> To divide functions into sections and then remove unused sections, I must
> provide flags "-fdata-sections" and "-ffunction-sections" in GCC and a flag
> "--gc-sections" in LD. Most of the build systems don't support these flags so
> GCC will generate bigger binaries.
> Is it possible to enable this feature without giving any command line flags manually?
All (at least decent) build systems support passing extra flags to the
compiler and linker (e.g. CXXFLAGS="-ffunction-sections"), or passing a
custom compiler and linker (which can set those flags, something like
CC="gcc -ffunction-sections"). This is how you should be setting such
flags.
If you're interested in DCE and other size-reducing optimizations, you
might also be interested in LTO and -Os.
--
Arsen Arsenović
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 381 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"?
2023-03-19 12:38 Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"? 3119369616.qq
2023-03-19 13:18 ` Arsen Arsenović
@ 2023-03-19 18:15 ` David Brown
1 sibling, 0 replies; 3+ messages in thread
From: David Brown @ 2023-03-19 18:15 UTC (permalink / raw)
To: 3119369616.qq, gcc
On 19/03/2023 13:38, 3119369616.qq via Gcc wrote:
> To divide functions into sections and then remove unused sections, I
> must provide flags "-fdata-sections" and "-ffunction-sections" in GCC
> and a flag "--gc-sections" in LD. Most of the build systems don't
> support these flags so GCC will generate bigger binaries. Is it
> possible to enable this feature without giving any command line
> flags manually?
Just to be clear here - removing unused sections is only beneficial if
you have a significant amount of unused code and data compiled in the
build. That can sometimes be the case, if you are making re-usable
library code. But for other types of code, it is better to be clear in
the source code about what is and is not part of the program - i.e., if
the function is not used by the program, it should not be in the source
code. I don't know what kind of code you are working on, but it's worth
considering.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-19 18:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19 12:38 Is it possible to enable data sections and function sections without explicitly giving flags "-fdata-sections" and "-ffunction-sections"? 3119369616.qq
2023-03-19 13:18 ` Arsen Arsenović
2023-03-19 18:15 ` David Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).