Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mold fails to hide dynamic symbols #277

Closed
Blendify opened this issue Jan 18, 2022 · 4 comments
Closed

Mold fails to hide dynamic symbols #277

Blendify opened this issue Jan 18, 2022 · 4 comments

Comments

@Blendify
Copy link

Environment

OS: Ubuntu 21.10
Mold: 1.0.1 built from main (43b2a1e)
GCC: 11.2.0

I also use ninja

Introduction

Hi, recently Blender added support to our build system however we found that symbols are not being hidden when using mold compared to other linkers.

I have been trying to isolate this down to a small reproducible case
but so far have not been able to create a small project.

I can guide you through building Blender though.

Reproduction Steps

Our build instructions can be found here: https://wiki.blender.org/wiki/Building_Blender/Linux

The easiest way to use MOLD is to enable the CMake option WITH_LINKER_MOLD.

Once built you can check for a symbol that should be hidden with nm -D ./blender | grep " T LLVM" compare this with the results of using a different linker such as enabling WITH_LINKER_LLD (make sure to disable mold also).

You can find our map file in blender.map

Desired results

nm -D ./blender | grep " T LLVM" should return nothing.

You could also try to run the application, building with mold should result in a crash during the program initialization.

@LazyDodo
Copy link

Sorry about this report, usually when we reach out to other projects we try not to file any "build all of blender" issues, @Blendify got a little trigger happy my apologies.

I extracted a minimal repro case below:

mold_version_issue.tar.gz

as you can see below, when linked with ld, B_func1 and B_func2 are no longer exported, however when linked with mold, both are still there.

root@SRV:/mnt/e/mold_test# mkdir build
root@SRV:/mnt/e/mold_test# cd build
root@SRV:/mnt/e/mold_test/build# cmake ..
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/e/mold_test/build
root@SRV:/mnt/e/mold_test/build# make
Scanning dependencies of target libB
[ 16%] Building C object CMakeFiles/libB.dir/b.c.o
[ 33%] Linking C static library liblibB.a
[ 33%] Built target libB
Scanning dependencies of target libA
[ 50%] Building C object CMakeFiles/libA.dir/a.c.o
[ 66%] Linking C static library liblibA.a
[ 66%] Built target libA
Scanning dependencies of target version_test
[ 83%] Building C object CMakeFiles/version_test.dir/vtest.c.o
[100%] Linking C shared library libversion_test.so
[100%] Built target version_test
root@SRV:/mnt/e/mold_test/build# readelf --dyn-syms ./libversion_test.so

Symbol table '.dynsym' contains 9 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.2.5 (2)
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     4: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
     5: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.2.5 (2)
     6: 000000000000118c    23 FUNC    GLOBAL DEFAULT   14 A_func1
     7: 0000000000001159    51 FUNC    GLOBAL DEFAULT   14 vtest
     8: 00000000000011a3    23 FUNC    GLOBAL DEFAULT   14 A_func2
root@SRV:/mnt/e/mold_test/build# cmake -DUSE_MOLD=On .
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/e/mold_test/build
root@SRV:/mnt/e/mold_test/build# make
[ 16%] Building C object CMakeFiles/libB.dir/b.c.o
[ 33%] Linking C static library liblibB.a
[ 33%] Built target libB
[ 50%] Building C object CMakeFiles/libA.dir/a.c.o
[ 66%] Linking C static library liblibA.a
[ 66%] Built target libA
[ 83%] Building C object CMakeFiles/version_test.dir/vtest.c.o
[100%] Linking C shared library libversion_test.so
[100%] Built target version_test
root@SRV:/mnt/e/mold_test/build# readelf --dyn-syms ./libversion_test.so

Symbol table '.dynsym' contains 11 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.2.5 (2)
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_finalize@GLIBC_2.2.5 (2)
     6: 0000000000001159    51 FUNC    GLOBAL DEFAULT   17 vtest
     7: 000000000000118c    23 FUNC    GLOBAL DEFAULT   17 A_func1
     8: 00000000000011a3    23 FUNC    GLOBAL DEFAULT   17 A_func2
     9: 00000000000011ba    23 FUNC    GLOBAL DEFAULT   17 B_func1
    10: 00000000000011d1    23 FUNC    GLOBAL DEFAULT   17 B_func2

@rui314
Copy link
Owner

rui314 commented Jan 19, 2022

I'm happy to fix the issue for Blender. Chances are there are many more programs that see the same issue in their builds. Let me take a look.

@rui314 rui314 closed this as completed in 809652d Jan 20, 2022
@Blendify
Copy link
Author

Can confirm the issue has been fixed, thanks again :)

@LazyDodo
Copy link

Mostly fixed, there's one other side case mold missed, but I'll file a separate bug for that one., since it's quite a different beast than this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants