owi icon indicating copy to clipboard operation
owi copied to clipboard

issue with getopt

Open redianthus opened this issue 10 months ago • 2 comments

wasm-ld-18: error: duplicate symbol: getopt
>>> defined in [...]/owi/_build/install/default/share/owi/c_files/libc.wasm
>>> defined in /tmp/test-1-11f16a.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang failed: run with --debug to get the full error message%

This is happening for instance on testcomp/sv-benchmarks/c/busybox-1.22.0/test-1.i

Probably related to the changes from #457

redianthus avatar Feb 21 '25 14:02 redianthus

OK so, I investigated a bit.

The Test-Comp C files are actually doing something like this:


#define _GNU_SOURCE
#include <getopt.h>
// ...

We could either:

  1. mark our getopt as weak (as I believe we've already been doing for other functions)
  2. pass a flag to allow multiple definitions in the linker
  3. make sure the symbol referenced from getopt.h is not pulled in (but that should already be the case because of --no-standard-libraries ?!)

My preference goes for the first one.

Actually, the Clang doc is basically empty about these options but reading the GCC one, I found that we probably want more than --no-standard-libraries and add -nodefaultlibs, I'll try with this one and see what happens...

redianthus avatar Feb 21 '25 15:02 redianthus

mark our getopt as weak (as I believe we've already been doing for other functions)

Maybe we should mark every symbol in our standard library as weak? It would probably avoid similar issues in the future

filipeom avatar Feb 21 '25 16:02 filipeom