Skip to contentSkip to conversation

Meson build on macOS: undefined symbol treatment

DISCUSSION Emmanuel Blot 3 participants 5 messages Aug 26, 2020 – Aug 31, 2020

lore
Share & tools
lore
#0 lore raw

Hi,

I’ve noticed that since meson builds have been enabled, on macOS, the build outcome with undefined symbols has changed:

- prior to meson introduction (v5.1.0):
* referencing an undeclared symbol in source code led to a warning at
compile stage
* referencing an undeclared symbol at link stage led to a fatal build
error (as usually expected)

- since meson introduction
* same behavior at compile stage
* however, the linker does silently generate an application - which
fails at launch since the symbol is undefined.

Step to reproduce:

from softmmu/main.c, replace for example call to qemu_init() with
qemu_init2();

- v5.1.0:
softmmu/main.c:48:5: warning: implicit declaration of function
'qemu_init2' is invalid in C99 [-Wimplicit-function-declaration]

    qemu_init2(argc, argv, envp);
      LINK    riscv64-softmmu/qemu-system-riscv64

Undefined symbols for architecture x86_64:
"_qemu_init2", referenced from:
_qemu_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[1]: *** [qemu-system-riscv64] Error 1

- current master:
softmmu/main.c:49:5: warning: implicit declaration of function
'qemu_init2' is invalid in C99 [-Wimplicit-function-declaration]

    qemu_init2(argc, argv, envp);
    ^

1 warning generated.
[3/3] Linking target qemu-system-riscv64

Quoted 1 line

riscv64-softmmu/qemu-system-riscv64

dyld: lazy symbol binding failed: Symbol not found: _qemu_init2
Referenced from:
/Users/eblot/Sources/Git/github.com/QEMU/upstream/build/riscv64-softmmu/qemu-system-riscv64
Expected in: flat namespace

'riscv64-softmmu/qemu-system-ris…' terminated by signal SIGABRT
(Abort)

This new behavior is likely to come from the linker flag:

-Wl,-undefined,dynamic_lookup

I’m not sure whether it is a new feature or a bug, but if the former stands true, is there a way to disable this feature?

Thanks,
Emmanuel.

#1 lore raw
Quoted 52 lines · Emmanuel Blot

Hi,

I’ve noticed that since meson builds have been enabled, on macOS, the build outcome with undefined symbols has changed:

- prior to meson introduction (v5.1.0):
  * referencing an undeclared symbol in source code led to a warning at compile stage
  * referencing an undeclared symbol at link stage led to a fatal build error (as usually expected)

- since meson introduction
  * same behavior at compile stage
  * however, the linker does silently generate an application - which fails at launch since the symbol is undefined.

Step to reproduce:

  from softmmu/main.c, replace for example call to qemu_init() with qemu_init2();

- v5.1.0:
  softmmu/main.c:48:5: warning: implicit declaration of function 'qemu_init2' is invalid in C99 [-Wimplicit-function-declaration] qemu_init2(argc, argv, envp);
      LINK    riscv64-softmmu/qemu-system-riscv64 Undefined symbols for architecture x86_64:
    "_qemu_init2", referenced from:
        _qemu_main in main.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[1]: *** [qemu-system-riscv64] Error 1

- current master:
  softmmu/main.c:49:5: warning: implicit declaration of function 'qemu_init2' is invalid in C99 [-Wimplicit-function-declaration] qemu_init2(argc, argv, envp);
    ^
  1 warning generated.
  [3/3] Linking target qemu-system-riscv64

 > riscv64-softmmu/qemu-system-riscv64
  dyld: lazy symbol binding failed: Symbol not found: _qemu_init2
    Referenced from:
/Users/eblot/Sources/Git/github.com/QEMU/upstream/build/riscv64-softmmu/qemu-system-riscv64

    Expected in: flat namespace

    'riscv64-softmmu/qemu-system-ris…' terminated by signal SIGABRT (Abort)

Quoted 6 lines

This new behavior is likely to come from the linker flag:

   -Wl,-undefined,dynamic_lookup

I’m not sure whether it is a new feature or a bug, but if the former stands true, is there a way to disable this feature?

Seems like this is added by meson itself (see meson/mesonbuild/linkers.py), not by our meson.build files ... Paolo, any idea why this happens?

Thomas

#2 lore raw
Quoted 3 lines · Thomas Huth

Seems like this is added by meson itself (see meson/mesonbuild/linkers.py), not by our meson.build files ... Paolo, any idea why this happens?

This is done by "b_lundef=false". I think it was added for modules, but maybe it's not necessary. Emmanuel, can you try removing it (line 3 of meson.build) and seeing if --enable-modules still works for you?

Paolo

#3 lore raw
Quoted 3 lines · Paolo Bonzini

This is done by "b_lundef=false". I think it was added for modules, but maybe it's not necessary. Emmanuel, can you try removing it (line 3 of meson.build) and seeing if --enable-modules still works for you?

Removing this option does restore the regular behavior on macOS (link stage fails whenever some symbols are missing), and QEMU still builds ok with —enable-modules option, but I have not actually tested this feature - I did not know it even existed. Do you want me to test some specific use cases?

Thanks,
Emmanuel.

#4 lore raw
Quoted 10 lines · Emmanuel Blot
Quoted 4 lines

This is done by "b_lundef=false".  I think it was added for modules, but maybe it's not necessary.  Emmanuel, can you try removing it (line 3 of meson.build) and seeing if --enable-modules still works for you?

Removing this option does restore the regular behavior on macOS (link stage fails whenever some symbols are missing), and QEMU still builds ok with --enable-modules option, but I have not actually tested this feature
- I did not know it even existed. Do you want me to test some specific use cases?

That's good enough for now, thanks!

Paolo