Is there a downside to using -Bsymbolic-functions?

前端 未结 4 761
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 12:54

I recently discovered the linker option \"-Bsymbolic-functions\" in GNU ld:

-Bsymbolic
  When creating a shared library, bind references to global symbols to         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 13:33

    Well you could say it is a "hardening" option as it ensures your calls to in-library functions surely end up there. But one issue that I found is some projects test-suites.

    For example the libvirt test-suite would want to call into the just built libvirt0.so but also mock some of the calls that will be done from there.

    Due to -Bsymbolic-functions being used on the build that breaks the test as the original and not the mocked function is called.

    Example backtraces Good case:

    #0  virHostCPUGetThreadsPerSubcore (arch=VIR_ARCH_PPC64) at ../../../tests/virhostcpumock.c:30
    #1  0x00007ffff7c1e4c4 in virHostCPUGetInfoPopulateLinux (cpuinfo=, arch=VIR_ARCH_PPC64, cpus=0x7fffffffdf38, mhz=, nodes=0x7fffffffdf40, sockets=0x7fffffffdf44, cores=0x7fffffffdf48, threads=0x7fffffffdf4c)
        at ../../../src/util/virhostcpu.c:661                                           
    #2  0x0000555555557e6f in linuxTestCompareFiles (outputfile=0x55555558f150 "/build/libvirt-OUKR8i/libvirt-4.10.0/tests/virhostcpudata/linux-ppc64-subcores2.expected", arch=VIR_ARCH_PPC64,·
        cpuinfofile=0x5555555a3f10 "/build/libvirt-OUKR8i/libvirt-4.10.0/tests/virhostcpudata/linux-ppc64-subcores2.cpuinfo") at ../../../tests/virhostcputest.c:44
    #3  linuxTestHostCPU (opaque=) at ../../../tests/virhostcputest.c:189
    #4  0x000055555555914d in virTestRun (title=0x55555555c0a1 "subcores2", body=0x555555557cc0 , data=0x7fffffffe0c0) at ../../../tests/testutils.c:176
    #5  0x000055555555781a in mymain () at ../../../tests/virhostcputest.c:263          
    #6  0x0000555555559df4 in virTestMain (argc=1, argv=0x7fffffffe2c8, func=0x5555555577b0 ) at ../../../tests/testutils.c:1114
    #7  0x00007ffff79bb09b in __libc_start_main (main=0x5555555576a0 
    , argc=1, argv=0x7fffffffe2c8, init=, fini=, rtld_fini=, stack_end=0x7fffffffe2b8) at ../csu/libc-start.c:308 #8 0x00005555555576ea in _start () at ../../../tests/virhostcputest.c:278

    Bad case:

    #0  virHostCPUGetThreadsPerSubcore (arch=arch@entry=VIR_ARCH_PPC64) at ../../../src/util/virhostcpu.c:1119
    #1  0x00007ffff7c27e04 in virHostCPUGetInfoPopulateLinux (cpuinfo=, arch=VIR_ARCH_PPC64, cpus=0x7fffffffdea8, mhz=, nodes=0x7fffffffdeb0, sockets=0x7fffffffdeb4, cores=0x7fffffffdeb8, threads=0x7fffffffdebc)
        at ../../../src/util/virhostcpu.c:661                                           
    #2  0x0000555555557e6f in linuxTestCompareFiles (outputfile=0x5555555a5c30 "/build/libvirt-4biJ7f/libvirt-4.10.0/tests/virhostcpudata/linux-ppc64-subcores2.expected", arch=VIR_ARCH_PPC64,·
        cpuinfofile=0x55555558fd20 "/build/libvirt-4biJ7f/libvirt-4.10.0/tests/virhostcpudata/linux-ppc64-subcores2.cpuinfo") at ../../../tests/virhostcputest.c:44
    #3  linuxTestHostCPU (opaque=) at ../../../tests/virhostcputest.c:189
    #4  0x000055555555914d in virTestRun (title=0x55555555c0a1 "subcores2", body=0x555555557cc0 , data=0x7fffffffe030) at ../../../tests/testutils.c:176
    #5  0x000055555555781a in mymain () at ../../../tests/virhostcputest.c:263          
    #6  0x0000555555559df4 in virTestMain (argc=1, argv=0x7fffffffe238, func=0x5555555577b0 ) at ../../../tests/testutils.c:1114
    #7  0x00007ffff79b009b in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
    #8  0x00005555555576ea in _start () at ../../../tests/virhostcputest.c:278 
    

    Compare the source for virHostCPUGetThreadsPerSubcore in those two and you will see the difference.

    Another case I have seen are:

    • static variables becoming multiple instances in singularity
    • segfaulting tests in sssd
    • autofs issues with global variables

    Since the original question was about potential drawbacks I thought it is worth to mention those somewhat common category of related issues as well.

提交回复
热议问题