Skip to content

Commit 320b5f4

Browse files
committed
[bazel/luajit.BUILD] Reinstate "-u" linker flag with external unwinder.
The flag is needed when the gold linker is used on Linux. (The LLD linker on Linux and macOS does not need it, nor does the LD64 linker on macOS.) The gold linker otherwise incorrectly removes this symbol when called with --gc-sections; it does not seem to recognize that the symbol is used as the personality routine in an eh_frame CIE entry. We are careful to not set this symbol as undefined when it is actually never defined, i.e. when using the internal unwinder, so as not to introduce undefined symbols into the final binary. (ELF linkers seem to ignore such undefined symbols if they are never referenced, but macOS's LD64 fails with "Undefined symbols" if it is not also called with "-undefined dynamic_lookup".
1 parent ffa7279 commit 320b5f4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bazel/luajit.BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ DEFINES = [
5050
},
5151
)
5252

53+
# This linker flag is needed only when using the gold linker: that linker does
54+
# not correctly retain the symbol "lj_err_unwind_dwarf" when --gc-sections is
55+
# used, and we need to request explicitly that that symbol be retained. Neither
56+
# LLD nor LD64 have this problem, but the flag also does not hurt those linkers.
57+
cc_library(
58+
name = "personality_linkopts",
59+
linkopts = select({
60+
"@platforms//os:linux": ["-ulj_err_unwind_dwarf"],
61+
"@platforms//os:macos": ["-u_lj_err_unwind_dwarf"],
62+
"//conditions:default": [],
63+
}),
64+
)
65+
5366
cc_library(
5467
name = "luajit",
5568
srcs = [
@@ -214,6 +227,10 @@ cc_library(
214227
includes = ["src"],
215228
linkopts = ["-ldl"],
216229
visibility = ["//visibility:public"],
230+
deps = select({
231+
":external_unwinder": [":personality_linkopts"],
232+
"//conditions:default": [],
233+
}),
217234
)
218235

219236
cc_binary(

0 commit comments

Comments
 (0)