Issue 91460
Summary [lld] --exclude-libs,ALL fails to work with both lto and version script is on
Labels lld
Assignees
Reporter mvpjox2233
    I tried to build my project with both lto, version script and exclude-libs,ALL. The result shows that the symbol in static library is global in the output file. I also tried with gcc and the same symbol is local.

Here is my test:
```
#====a.cpp====
#include <stdio.h>
void a()
{
 printf("func a\n");
}
#====b.cpp====
#include <stdio.h>
void b()
{
    printf("func b\n");
}
#====c.cpp====
#include <stdio.h>
void c()
{
    printf("func c\n");
}
#====main.cpp====
#include <stdio.h>
void a();
void b();
void c();
int main()
{
    a();
    b();
    c();
 printf("func main\n");
}

#====map.txt====
{
 global:
        extern "C++" {
            a*;
            b*;
 c*;
        };
    local:
 *;
};
```

build command:
```
CC=/usr/workspace/clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04/bin/clang++
AR=/usr/workspace/clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-ar
${CC} -c a.cpp -flto -fvisibility=default -o a.lto
${CC} -c b.cpp -flto -fvisibility=default -o b.lto
${CC} -c c.cpp -flto -fvisibility=default -o c.lto
${CC} -c main.cpp -flto -fvisibility=default -o main.lto
${AR} -cr s.lta a.lto b.lto c.lto
${CC} -flto main.lto -Wl,--whole-archive s.lta -Wl,--no-whole-archive -shared -o main.ltout -fvisibility=default -Wl,--exclude-libs,ALL -fuse-ld=lld
```

The symbol table of `main.ltout` is :
```
     6: 0000000000001680    20 FUNC    GLOBAL DEFAULT    11 _Z1av
     7: 00000000000016a0    20 FUNC    GLOBAL DEFAULT 11 _Z1bv
     8: 00000000000016c0    20 FUNC    GLOBAL DEFAULT    11 _Z1cv
```

With `CC=g++` and `AR=ar` in build command, the symbol table can be:
```
    11: 0000000000001146    26 FUNC    LOCAL  DEFAULT 14 _Z1av
    12: 0000000000001160    26 FUNC    LOCAL  DEFAULT    14 _Z1bv
    13: 000000000000117a    26 FUNC    LOCAL  DEFAULT    14 _Z1cv
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to