Skip to content

Commit

Permalink
[Linux] Only export extension init symbol
Browse files Browse the repository at this point in the history
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
export its symbols.
  • Loading branch information
Faless committed Dec 22, 2023
1 parent ec0eded commit a4f49d8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
30 changes: 18 additions & 12 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -175,6 +163,23 @@ 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.
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":
Expand All @@ -190,6 +195,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
Expand Down
6 changes: 6 additions & 0 deletions misc/dist/linux/symbols-extension.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
global:
webrtc_extension_init;
local:
*;
};
9 changes: 9 additions & 0 deletions misc/dist/linux/symbols-gdnative.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
global:
godot_gdnative_singleton;
godot_gdnative_init;
godot_gdnative_terminate;
godot_nativescript_init;
local:
*;
};
6 changes: 4 additions & 2 deletions tools/openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -223,8 +227,6 @@ def exists(env):


def generate(env):
env.AddMethod(build_openssl, "OpenSSL")

# Check if the user specified infos about external OpenSSL files.
external_opts = ["openssl_external_crypto", "openssl_external_ssl", "openssl_external_include"]
is_set = lambda k: env.get(k, "") != ""
Expand Down
2 changes: 2 additions & 0 deletions tools/rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down

0 comments on commit a4f49d8

Please sign in to comment.