emscripten-core / emscripten-core/emscripten

Bug: undefined exported symbol when symbols file contain unused symbols

Open
#21,516 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Version: 3.1.52 onwards

Steps to reproduce:

```
//hello.c

#include

void hello_world() {
printf("Hello, World!\n");
}

```

Where the symfile is:
```
_hello_world
_unused_symbol
```

Now in terminal, run:
```
$ emcc -fPIC -c src/hello.c -fPIC -DPIC -o src/hello.o
$ emcc -sSIDE_MODULE=2 -sEXPORTED_FUNCTIONS=@symfile -o hello.so src/hello.o
```

This should give the error:
emcc: error: undefined exported symbol: "_unused_symbol" [-Wundefined] [-Werror]
Expected:
hello.so should be compiled without any errors.

More information:

This bug is introduced in 3.1.52. With the commit 7e808f1

GCC does not generate error in such situation.
To demonstrate, if the symfile file were:

```
hello_world
unused_symbol
```

Running this in terminal would generate hello.so **without any issues**:

```
gcc -fPIC -c src/hello.c -fPIC -DPIC -o src/hello.o
gcc -shared -Wl,--retain-symbols-file=symfile -o hello.so src/hello.o
```

Is this error: "undefined exported symbol" introduced from 7e808f1
expected behavior or is it a bug? Many projects use only one symbol file
in whole project, and gcc seems to allow it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.