build: compiler flags in linker flags output #31487

issue fanquake openend this issue on December 13, 2024
  1. fanquake commented at 1:17 pm on December 13, 2024: member

    This is confusing / undermines the output printed, so it’d be good if it could be improved, or fixed entirely.

    Seeing:

    0Linker flags .......................... <a bunch of compiler flags> i.e `-ftrivial-auto-var-init=pattern`
    

    just doesn’t make sense.

  2. fanquake added the label Build system on Dec 13, 2024
  3. fanquake added this to the milestone 29.0 on Dec 13, 2024
  4. hebasto commented at 1:29 pm on December 13, 2024: member

    The CMAKE_<LANG>_FLAGS are applied language-wide, which means:

    These flags will be passed to all invocations of the compiler. This includes invocations that drive compiling and those that drive linking.

    Passing {C,CXX}FLAGS variables when using Autotools exhibits the same behaviour.

  5. fanquake commented at 1:36 pm on December 13, 2024: member

    Passing {C,CXX}FLAGS variables when using Autotools exhibits the same behaviour.

    No it doesn’t:

    0./autogen.sh && ./configure CXXFLAGS="-ftrivial-auto-var-init=pattern"
    1  CXXFLAGS        =  -g -O2  -fdebug-prefix-map=$(abs_top_srcdir)=.  -Wstack-protector -fstack-protector-all -mbranch-protection=bti  -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wthread-safety -Wloop-analysis -Wredundant-decls -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wdocumentation -Wself-assign -Wundef  -Wno-unused-parameter   -ftrivial-auto-var-init=pattern
    2  LDFLAGS         = -lpthread  -Wl,-fixup_chains   -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-dead_strip_dylibs 
    

    My point is not what may or may not be happening behinds the scenes, my point is we are presenting output doesn’t make sense.

  6. hebasto commented at 2:26 pm on December 13, 2024: member

    Passing {C,CXX}FLAGS variables when using Autotools exhibits the same behaviour.

    No it doesn’t:

    0./autogen.sh && ./configure CXXFLAGS="-ftrivial-auto-var-init=pattern"
    1  CXXFLAGS        =  -g -O2  -fdebug-prefix-map=$(abs_top_srcdir)=.  -Wstack-protector -fstack-protector-all -mbranch-protection=bti  -Wall -Wextra -Wgnu -Wformat -Wformat-security -Wvla -Wshadow-field -Wthread-safety -Wloop-analysis -Wredundant-decls -Wunused-member-function -Wdate-time -Wconditional-uninitialized -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wdocumentation -Wself-assign -Wundef  -Wno-unused-parameter   -ftrivial-auto-var-init=pattern
    2  LDFLAGS         = -lpthread  -Wl,-fixup_chains   -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-dead_strip_dylibs 
    

    It does:

    0$ ./autogen.sh && ./configure CXXFLAGS="-ftrivial-auto-var-init=pattern"
    1$ make src/bitcoind V=1 | grep -e "-ftrivial-auto-var-init=pattern"
    2...
    3/bin/bash ../libtool  --tag=CXX --preserve-dup-deps  --mode=link /usr/bin/ccache g++ -std=c++20 -g -O2 -fno-extended-identifiers -fstack-reuse=none -fdebug-prefix-map=/home/hebasto/git/bitcoin=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wundef -Wno-unused-parameter   -fPIE -ftrivial-auto-var-init=pattern   -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -pie    -pthread -lpthread  -o bitcoind bitcoind-bitcoind.o  init/bitcoind-bitcoind.o libbitcoin_node.a libbitcoin_wallet.a libbitcoin_common.a libbitcoin_util.a libunivalue.la libbitcoin_zmq.a libbitcoin_consensus.a crypto/libbitcoin_crypto_base.la crypto/libbitcoin_crypto_sse41.la crypto/libbitcoin_crypto_x86_shani.la crypto/libbitcoin_crypto_avx2.la  leveldb/libleveldb.la crc32c/libcrc32c.la crc32c/libcrc32c_sse42.la  leveldb/libmemenv.la secp256k1/libsecp256k1.la  -lminiupnpc -lnatpmp -levent_pthreads -levent  -levent  -lzmq  -lsqlite3  
    4libtool: link: /usr/bin/ccache g++ -std=c++20 -g -O2 -fno-extended-identifiers -fstack-reuse=none -fdebug-prefix-map=/home/hebasto/git/bitcoin=. -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wundef -Wno-unused-parameter -fPIE -ftrivial-auto-var-init=pattern -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-z -Wl,separate-code -pie -o bitcoind bitcoind-bitcoind.o init/bitcoind-bitcoind.o  -lpthread libbitcoin_node.a libbitcoin_wallet.a libbitcoin_common.a libbitcoin_util.a ./.libs/libunivalue.a libbitcoin_zmq.a libbitcoin_consensus.a crypto/.libs/libbitcoin_crypto_base.a crypto/.libs/libbitcoin_crypto_sse41.a crypto/.libs/libbitcoin_crypto_x86_shani.a crypto/.libs/libbitcoin_crypto_avx2.a leveldb/.libs/libleveldb.a crc32c/.libs/libcrc32c.a crc32c/.libs/libcrc32c_sse42.a leveldb/.libs/libmemenv.a secp256k1/.libs/libsecp256k1.a -lminiupnpc -lnatpmp -levent_pthreads -levent -levent -lzmq -lsqlite3 -pthread
    

    The point is that CMake correctly reports the flags passed during the linkage step, whereas Autotools fails to do so.

    My point is not what may or may not be happening behinds the scenes

    Nothing is “happening behinds the scenes”. Rather, everything is well documented in the CMake docs.

    my point is we are presenting output doesn’t make sense.

    The following diff might help:

     0--- a/cmake/module/FlagsSummary.cmake
     1+++ b/cmake/module/FlagsSummary.cmake
     2@@ -34,10 +34,8 @@ function(print_flags_per_config config indent_num)
     3   string(STRIP "${combined_cxx_flags} ${APPEND_CXXFLAGS}" combined_cxx_flags)
     4   indent_message("C++ compiler flags ...................." "${combined_cxx_flags}" ${indent_num})
     5 
     6-  string(STRIP "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${config_uppercase}}" combined_linker_flags)
     7-  string(STRIP "${combined_linker_flags} ${CMAKE_EXE_LINKER_FLAGS}" combined_linker_flags)
     8   get_target_interface(common_link_options "${config}" core_interface LINK_OPTIONS)
     9-  string(STRIP "${combined_linker_flags} ${common_link_options}" combined_linker_flags)
    10+  string(STRIP "${CMAKE_EXE_LINKER_FLAGS} ${common_link_options}" combined_linker_flags)
    11   if(CMAKE_CXX_LINK_PIE_SUPPORTED)
    12     string(JOIN " " combined_linker_flags ${combined_linker_flags} ${CMAKE_CXX_LINK_OPTIONS_PIE})
    13   endif()
    


fanquake hebasto

Labels
Build system

Milestone
29.0


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me