diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-12-21 19:05:53 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-12-22 01:30:01 +0100 |
commit | b0efc17d3b898206c2e1c98ad4884e404808c854 (patch) | |
tree | 8fe3c7cc594db1ee2b07fb391002870440e65880 | |
parent | ec0ededcdef7512517aa7aaa9bd49652cece4770 (diff) | |
download | fork-godot-webrtc-native-b0efc17d3b898206c2e1c98ad4884e404808c854.tar.gz fork-godot-webrtc-native-b0efc17d3b898206c2e1c98ad4884e404808c854.tar.bz2 fork-godot-webrtc-native-b0efc17d3b898206c2e1c98ad4884e404808c854.zip |
[Linux] Only export extension init symbol
Since we link with static libstdc++ we need to tell gcc to only export
the necessary symbols.
Using "-fvisibility=hidden" will not work, since libstdc++ explicitly
exports its symbols.
-rw-r--r-- | SConstruct | 31 | ||||
-rw-r--r-- | misc/dist/linux/symbols-extension.map | 6 | ||||
-rw-r--r-- | misc/dist/linux/symbols-gdnative.map | 9 | ||||
-rw-r--r-- | tools/openssl.py | 4 | ||||
-rw-r--r-- | tools/rtc.py | 2 |
5 files changed, 40 insertions, 12 deletions
@@ -120,18 +120,6 @@ if env["platform"] == "macos" and os.environ.get("OSXCROSS_ROOT", ""): if env["macos_deployment_target"] != "default": env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = env["macos_deployment_target"] -# Patch linux flags to statically link libgcc and libstdc++ -if env["platform"] == "linux": - env.Append( - LINKFLAGS=[ - "-Wl,--no-undefined", - "-static-libgcc", - "-static-libstdc++", - ] - ) - # And add some linux dependencies. - env.Append(LIBS=["pthread", "dl"]) - opts.Update(env) target = env["target"] @@ -175,6 +163,24 @@ rtc = env.BuildLibDataChannel(ssl) # but it's better to be safe in case of indirect inclusions by one of our other dependencies. env.Depends(sources, ssl + rtc) +# We want to statically link against libstdc++ on Linux to maximize compatibility, but we must restrict the exported +# symbols using a GCC version script, or we might end up overriding symbols from other libraries. +# Using "-fvisibility=hidden" will not work, since libstdc++ explicitly exports its symbols. +symbols_file = None +if env["platform"] == "linux": + if env["godot_version"] == "3": + symbols_file = env.File("misc/dist/linux/symbols-gdnative.map") + else: + symbols_file = env.File("misc/dist/linux/symbols-extension.map") + env.Append( + LINKFLAGS=[ + "-Wl,--no-undefined,--version-script=" + symbols_file.abspath, + "-static-libgcc", + "-static-libstdc++", + ] + ) + env.Depends(sources, symbols_file) + # Make the shared library result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"]) if env["godot_version"] != "3" and env["platform"] == "macos": @@ -190,6 +196,7 @@ if env["godot_version"] != "3" and env["platform"] == "macos": library = [library_file, plist_file] else: library = env.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources) + Default(library) # GDNativeLibrary diff --git a/misc/dist/linux/symbols-extension.map b/misc/dist/linux/symbols-extension.map new file mode 100644 index 0000000..5af224e --- /dev/null +++ b/misc/dist/linux/symbols-extension.map @@ -0,0 +1,6 @@ +{ + global: + webrtc_extension_init; + local: + *; +}; diff --git a/misc/dist/linux/symbols-gdnative.map b/misc/dist/linux/symbols-gdnative.map new file mode 100644 index 0000000..d048dc3 --- /dev/null +++ b/misc/dist/linux/symbols-gdnative.map @@ -0,0 +1,9 @@ +{ + global: + godot_gdnative_singleton; + godot_gdnative_init; + godot_gdnative_terminate; + godot_nativescript_init; + local: + *; +}; diff --git a/tools/openssl.py b/tools/openssl.py index f42928f..7b18210 100644 --- a/tools/openssl.py +++ b/tools/openssl.py @@ -125,6 +125,8 @@ def build_openssl(env, jobs=None): env.Prepend(LIBPATH=[env["SSL_BUILD"]]) if env["platform"] == "windows": env.PrependUnique(LIBS=["crypt32", "ws2_32", "advapi32", "user32"]) + if env["platform"] == "linux": + env.PrependUnique(LIBS=["pthread", "dl"]) env.Prepend(LIBS=env["SSL_LIBS"]) return [env["SSL_CRYPTO_LIBRARY"], env["SSL_LIBRARY"]] @@ -169,6 +171,8 @@ def build_openssl(env, jobs=None): env.Prepend(LIBPATH=[env["SSL_BUILD"]]) if env["platform"] == "windows": env.PrependUnique(LIBS=["crypt32", "ws2_32", "advapi32", "user32"]) + if env["platform"] == "linux": + env.PrependUnique(LIBS=["pthread", "dl"]) env.Prepend(LIBS=env["SSL_LIBS"]) return ssl diff --git a/tools/rtc.py b/tools/rtc.py index 6882bb4..b4d9173 100644 --- a/tools/rtc.py +++ b/tools/rtc.py @@ -37,6 +37,8 @@ def build_library(env, ssl): # Configure env. if env["platform"] == "windows": env.PrependUnique(LIBS=["iphlpapi", "bcrypt"]) + if env["platform"] == "linux": + env.PrependUnique(LIBS=["pthread"]) env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), rtc))) env.Append(CPPPATH=["#thirdparty/libdatachannel/include"]) |