Skip to content

Commit

Permalink
[bazel/luajit.BUILD] Reinstate "-u" linker flag with external unwinder.
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
tkoeppe committed Jun 7, 2023
1 parent ffa7279 commit 320b5f4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bazel/luajit.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ DEFINES = [
},
)

# This linker flag is needed only when using the gold linker: that linker does
# not correctly retain the symbol "lj_err_unwind_dwarf" when --gc-sections is
# used, and we need to request explicitly that that symbol be retained. Neither
# LLD nor LD64 have this problem, but the flag also does not hurt those linkers.
cc_library(
name = "personality_linkopts",
linkopts = select({
"@platforms//os:linux": ["-ulj_err_unwind_dwarf"],
"@platforms//os:macos": ["-u_lj_err_unwind_dwarf"],
"//conditions:default": [],
}),
)

cc_library(
name = "luajit",
srcs = [
Expand Down Expand Up @@ -214,6 +227,10 @@ cc_library(
includes = ["src"],
linkopts = ["-ldl"],
visibility = ["//visibility:public"],
deps = select({
":external_unwinder": [":personality_linkopts"],
"//conditions:default": [],
}),
)

cc_binary(
Expand Down

0 comments on commit 320b5f4

Please sign in to comment.