Ignore:
Timestamp:
07/02/2023 12:33:53 PM (12 months ago)
Author:
Xi Ruoyao <xry111@…>
Branches:
12.0, 12.1, kea, ken/TL2024, ken/tuningfonts, lazarus, plabs/newcss, python3.11, rahul/power-profiles-daemon, renodr/vulkan-addition, trunk, xry111/llvm18, xry111/xf86-video-removal
Children:
6feca4d
Parents:
6efdfbe
Message:

building-notes: Mention -Wl,{-O1,--as-needed} and -fno-semantic-interposition for optimization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • introduction/important/building-notes.xml

    r6efdfbe r9b61265  
    987987        <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar>. For an
    988988        introduction to the options available with gcc and g++ see <ulink
    989         url="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html"/> and <ulink
    990         url="https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html"/>
    991         and <command>info gcc</command>.
    992 
     989        url="https://gcc.gnu.org/onlinedocs/gcc-&gcc-version;/gcc/Optimize-Options.html"/>.
     990        The same content can be also found in <command>info gcc</command>.
    993991      </para>
    994992
     
    10361034
    10371035      <para>
     1036        When a shared library is built by GCC, a feature named
     1037        <quote>semantic interposition</quote> is enabled by default.  When
     1038        the shared library refers to a symbol name with external linkage
     1039        and default visbility, if the symbol exists in both the shared
     1040        library and the main executable, semantic interposition guarantees
     1041        the symbol in the main executable is always used.  This feature
     1042        was invented in an attempt to make the behavior of linking a shared
     1043        library and linking a static library as similar as possible.  Today
     1044        only a small number of packages still depend on semantic
     1045        interposition, but the feature is still on by the default of GCC,
     1046        causing many optimizations disabled for shared libraries because
     1047        they conflict with semantic interposition.  The
     1048        <option>-fno-semantic-interposition</option> option can be passed
     1049        to <command>gcc</command> or <command>g++</command> to disable
     1050        semantic interposition and enable more optimizations for shared
     1051        libraries.  This option is used as the default of some packages
     1052        (for example <xref linkend='python3'/>), and it's also the default
     1053        of Clang.
     1054      </para>
     1055
     1056      <para>
    10381057        There are also various other options which some people claim are
    10391058        beneficial. At worst, you get to recompile and test, and then
     
    10461065        used are those which were used by those <quote>parent</quote>
    10471066        packages.
     1067      </para>
     1068
     1069      <para>
     1070        For <envar>LDFLAGS</envar>, there are two options can be used
     1071        for optimization.  With <option>-Wl,-O1</option>, the linker will
     1072        optimize the hash table to speed up the dynamic linking.  And with
     1073        <option>-Wl,--as-needed</option>, the linker will disregard
     1074        unnecessary <option>-l<replaceable>foo</replaceable></option> options
     1075        from the command line, i. e. the shared library <systemitem
     1076        class='library'>lib<replaceable>foo</replaceable></systemitem>
     1077        will only be linked if a symbol in <systemitem
     1078        class='library'>lib<replaceable>foo</replaceable></systemitem> is
     1079        really referred from the executable or shared library being linked.
     1080        This can sometimes mitigate the <quote>excessive dependencies to
     1081        shared librarues</quote> issues caused by
     1082        <application>libtool</application>.  Note that the
     1083        <option>-Wl,</option> prefix is necessary because despite the
     1084        variable is named <envar>LDFLAGS</envar>, its content is actually
     1085        passed to <command>gcc</command> (or <command>g++</command>,
     1086        <command>clang</command>, etc.) during the link stage, not directly
     1087        passed to <command>ld</command>.
     1088      </para>
     1089
     1090      <para>
     1091        Note that <option>-Wl,-O1</option> is completely unrelated to the
     1092        compiler optimization flag <option>-O1</option>.  Some packages are
     1093        using <option>-Wl,-O1</option> and <option>-Wl,--as-needed</option>
     1094        as the default in their building systems.
    10481095      </para>
    10491096
Note: See TracChangeset for help on using the changeset viewer.