Skip to content

Commit b0efc17

Browse files
committed
[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.
1 parent ec0eded commit b0efc17

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

SConstruct

+19-12
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,6 @@ if env["platform"] == "macos" and os.environ.get("OSXCROSS_ROOT", ""):
120120
if env["macos_deployment_target"] != "default":
121121
env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = env["macos_deployment_target"]
122122

123-
# Patch linux flags to statically link libgcc and libstdc++
124-
if env["platform"] == "linux":
125-
env.Append(
126-
LINKFLAGS=[
127-
"-Wl,--no-undefined",
128-
"-static-libgcc",
129-
"-static-libstdc++",
130-
]
131-
)
132-
# And add some linux dependencies.
133-
env.Append(LIBS=["pthread", "dl"])
134-
135123
opts.Update(env)
136124

137125
target = env["target"]
@@ -175,6 +163,24 @@ rtc = env.BuildLibDataChannel(ssl)
175163
# but it's better to be safe in case of indirect inclusions by one of our other dependencies.
176164
env.Depends(sources, ssl + rtc)
177165

166+
# We want to statically link against libstdc++ on Linux to maximize compatibility, but we must restrict the exported
167+
# symbols using a GCC version script, or we might end up overriding symbols from other libraries.
168+
# Using "-fvisibility=hidden" will not work, since libstdc++ explicitly exports its symbols.
169+
symbols_file = None
170+
if env["platform"] == "linux":
171+
if env["godot_version"] == "3":
172+
symbols_file = env.File("misc/dist/linux/symbols-gdnative.map")
173+
else:
174+
symbols_file = env.File("misc/dist/linux/symbols-extension.map")
175+
env.Append(
176+
LINKFLAGS=[
177+
"-Wl,--no-undefined,--version-script=" + symbols_file.abspath,
178+
"-static-libgcc",
179+
"-static-libstdc++",
180+
]
181+
)
182+
env.Depends(sources, symbols_file)
183+
178184
# Make the shared library
179185
result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
180186
if env["godot_version"] != "3" and env["platform"] == "macos":
@@ -190,6 +196,7 @@ if env["godot_version"] != "3" and env["platform"] == "macos":
190196
library = [library_file, plist_file]
191197
else:
192198
library = env.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
199+
193200
Default(library)
194201

195202
# GDNativeLibrary

misc/dist/linux/symbols-extension.map

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
global:
3+
webrtc_extension_init;
4+
local:
5+
*;
6+
};

misc/dist/linux/symbols-gdnative.map

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
global:
3+
godot_gdnative_singleton;
4+
godot_gdnative_init;
5+
godot_gdnative_terminate;
6+
godot_nativescript_init;
7+
local:
8+
*;
9+
};

tools/openssl.py

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def build_openssl(env, jobs=None):
125125
env.Prepend(LIBPATH=[env["SSL_BUILD"]])
126126
if env["platform"] == "windows":
127127
env.PrependUnique(LIBS=["crypt32", "ws2_32", "advapi32", "user32"])
128+
if env["platform"] == "linux":
129+
env.PrependUnique(LIBS=["pthread", "dl"])
128130
env.Prepend(LIBS=env["SSL_LIBS"])
129131
return [env["SSL_CRYPTO_LIBRARY"], env["SSL_LIBRARY"]]
130132

@@ -169,6 +171,8 @@ def build_openssl(env, jobs=None):
169171
env.Prepend(LIBPATH=[env["SSL_BUILD"]])
170172
if env["platform"] == "windows":
171173
env.PrependUnique(LIBS=["crypt32", "ws2_32", "advapi32", "user32"])
174+
if env["platform"] == "linux":
175+
env.PrependUnique(LIBS=["pthread", "dl"])
172176
env.Prepend(LIBS=env["SSL_LIBS"])
173177

174178
return ssl

tools/rtc.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def build_library(env, ssl):
3737
# Configure env.
3838
if env["platform"] == "windows":
3939
env.PrependUnique(LIBS=["iphlpapi", "bcrypt"])
40+
if env["platform"] == "linux":
41+
env.PrependUnique(LIBS=["pthread"])
4042
env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), rtc)))
4143
env.Append(CPPPATH=["#thirdparty/libdatachannel/include"])
4244

0 commit comments

Comments
 (0)