bpo-36508: python-config don't export LINKFORSHARED by vstinner · Pull Request #12661 · python/cpython (original) (raw)

I tested manually, the change works as expected.

Without the change (master branch), --ldflags contains -Xlinker -export-dynamic:

$ git clean -fdx; ./configure --with-pydebug -C && make

$ ./python python-config.py --ldflags
-L/usr/local/lib/python3.8/config-3.8dm-x86_64-linux-gnu -lpython3.8dm -lcrypt -lpthread -ldl -lutil -lm -lm -Xlinker -export-dynamic

$ bash python-config --ldflags
-L/home/vstinner/prog/python/lib/python3.8/config-3.8dm-x86_64-linux-gnu -L/home/vstinner/prog/python/lib -lpython3.8dm -lcrypt -lpthread -ldl  -lutil -lm -lm  -Xlinker -export-dynamic

With the change, --ldflags doesn't contain -Xlinker -export-dynamic:

$ git clean -fdx; ./configure --with-pydebug -C && make

$ ./python python-config.py --ldflags
-L/usr/local/lib/python3.8/config-3.8dm-x86_64-linux-gnu -lpython3.8dm -lcrypt -lpthread -ldl -lutil -lm -lm

$ bash python-config --ldflags
-L/home/vstinner/prog/python/lib/python3.8/config-3.8dm-x86_64-linux-gnu -L/home/vstinner/prog/python/lib -lpython3.8dm -lcrypt -lpthread -ldl  -lutil -lm -lm 

I'm not sure why python-config (shell) and python-config.py (Python) return different output for --ldflags (this behavior can be seen without my change, my change isn't related to that).


Note: (with or without the change) configure and Python don't add any LDFLAGS on my Fedora 29:

$ ./python -m sysconfig|grep LDFLAGS
    CONFIGURE_LDFLAGS = ""
    CONFIGURE_LDFLAGS_NODIST = ""
    LDFLAGS = ""
    LDFLAGS_NODIST = ""
    OPENSSL_LDFLAGS = ""
    PY_CORE_LDFLAGS = ""
    PY_LDFLAGS = ""
    PY_LDFLAGS_NODIST = ""

python3 from Fedora 29 contains way more LDFLAGS:

$ python3 -m sysconfig|grep LDFLAGS
    CONFIGURE_LDFLAGS = "-Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g"
    CONFIGURE_LDFLAGS_NODIST = "-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g"
    CONFIG_ARGS = "'--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--enable-ipv6' '--enable-shared' '--with-computed-gotos=yes' '--with-dbmliborder=gdbm:ndbm:bdb' '--with-system-expat' '--with-system-ffi' '--enable-loadable-sqlite-extensions' '--with-dtrace' '--with-lto' '--with-ssl-default-suites=openssl' '--with-valgrind' '--without-ensurepip' '--enable-optimizations' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv ' 'LDFLAGS=-Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g ' 'CPPFLAGS=' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'"
    LDFLAGS = "-Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g"
    OPENSSL_LDFLAGS = ""
    PY_CORE_LDFLAGS = "-Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g"
    PY_LDFLAGS = "-Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -g"
    PY_LDFLAGS_NODIST = "-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g"