Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llcppsymg:linux compatibility #830

Open
4 of 8 tasks
luoliwoshang opened this issue Oct 15, 2024 · 0 comments · May be fixed by #788
Open
4 of 8 tasks

llcppsymg:linux compatibility #830

luoliwoshang opened this issue Oct 15, 2024 · 0 comments · May be fixed by #788

Comments

@luoliwoshang
Copy link
Contributor

luoliwoshang commented Oct 15, 2024

nm tool

dynamic symbol

using the nm tool to examine dynamic libraries, have discovered significant differences between macOS and Linux:
On Linux:

  • The -D flag must be specified to obtain the corresponding symbols.
  • Without -D, no symbols are displayed.
root@be00d9b1c2c9:/lib/aarch64-linux-gnu# nm -gU liblua5.4.so
nm: liblua5.4.so: no symbols
root@be00d9b1c2c9:/lib/aarch64-linux-gnu# nm -gDU liblua5.4.so
0000000000000000 A LUA_5.4
0000000000026a40 T luaL_addgsub@@LUA_5.4
00000000000269a0 T luaL_addlstring@@LUA_5.4
0000000000026a04 T luaL_addstring@@LUA_5.4

On macOS:

  • There's no -D flag. The nm command displays all symbols (including dynamic ones) by default.
❯ nm -gDU libcjson.dylib
/Library/Developer/CommandLineTools/usr/bin/nm: error: libcjson.dylib: File format has no dynamic symbol table
homebrew/lib on stable via v21.7.2
❯ nm -gU libcjson.dylib
0000000000002ab8 T cJSON_AddArrayToObject
0000000000002720 T cJSON_AddBoolToObject
0000000000002690 T cJSON_AddFalseToObject
0000000000002440 T cJSON_AddItemReferenceToArray
0000000000002520 T cJSON_AddItemReferenceToObject
homebrew/lib on stable via v21.7.2

The reason for this difference is that macOS and Linux use different formats for their executable files and handle symbol tables differently:

symbol version

On Linux, symbols may appear with version declarations separated by @@
https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

dynamic lib search

pkg-config

On Linux systems, the pkg-config --libs command does not output the -L path for dynamic libraries installed in the system's default search paths

For example:
root@be00d9b1c2c9:/usr/lib/aarch64-linux-gnu# pkg-config --libs lua5.4
-llua5.4

This output only includes the -l flag to specify the library name, but does not include the -L flag to specify the library path. This is because the library is located in the system's default search path.

will search valid path from below conf
/etc/ld.so.conf.d/*.conf
/etc/ld.so.conf

so & dylib

On Linux, dynamic library names end with .so

  • .so in linux,.dylib in macos

Related Bugs & Patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant