Issue 86777
Summary [lld] why does lld export hidden symbols without warning when dynamic libraries link to object files?
Labels lld
Assignees
Reporter Zhenhang1213
    When I compile .o with two c files -fvisibility=hidden,and a.c depends on a function of b.c. then generates bit dynamic libraries of a.c, Finally define a main function in the new file to generate executable files together, there will be an error using ld, but not lld.

code:
a.c:

```
#include<stdio.h>
#include"a.h"

int main1(void) {
    printf("main1\n");
    return 0;
}
```
a.h:

`int main1(void);`
b.c:

```
#include<stdio.h>
#include"a.h"

extern int main1();

int shared1(void) {
      printf("shared1\n");
      main1();
      return 0;
}
```
main.c:

```
int main(void) {
    return 0;
}
```
and the compiler Commands is:
```
clang -fvisibility=hidden -o a.o  -c a.c
clang -fvisibility=hidden -o main.o  -c main.c
clang -fvisibility=hidden -o b.o  -c b.c
clang -shared -Wl,-soname,libb.so -o libb.so b.o
clang -fuse-ld=ld  -o main.out  main.o a.o libb.so
```
error:
```
/usr/bin/ld: main.out: hidden symbol `main1' in a.o is referenced by DSO
/usr/bin/ld: final link failed: bad value
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
```
without any error or warning:
clang -fuse-ld=lld  -o main.out  main.o a.o libb.so



_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to