Skip to content

Commit fc84e84

Browse files
committed
openkal-musl: name this system's own linker, for the fifteen indirect symbols
1 parent 7fd2be4 commit fc84e84

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

mcpp.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,23 @@ ldflags = ["-nostdlib", "-static", "-Wl,--no-dynamic-linker",
168168
# is loaded. This format has no such headers, and the operation it names is one
169169
# openkal does not offer in any case.
170170
sources = ["!musl/src/ldso/dl_iterate_phdr.c"]
171-
ldflags = ["-nostdlib", "-lSystem", "-Wl,-e,_okm_start", "-Wl,-dead_strip"]
171+
#
172+
# --ld-path names this system's own linker rather than the one the toolchain
173+
# brings. The reason is one construct and fifteen uses of it. A second name for
174+
# a definition is made here with the assembler's own directive; where the
175+
# definition is in the same translation unit that produces an ordinary symbol,
176+
# and where it is not --- fifteen names in musl, every one of them a function
177+
# declared in a header and defined elsewhere --- it produces an indirect symbol,
178+
# which is what that directive is for. The toolchain's linker refuses an
179+
# indirect symbol, in as many words: "TODO: support aliasing to symbols of kind
180+
# 1". This system's own linker is the one the format was designed alongside and
181+
# resolves them.
182+
#
183+
# The measurement: 1154 of musl's translation units compiled for this system
184+
# produce fifteen indirect symbols between them, and they are listed in
185+
# musl/PATCHES.md.
186+
ldflags = ["-nostdlib", "-lSystem", "--ld-path=/usr/bin/ld",
187+
"-Wl,-e,_okm_start", "-Wl,-dead_strip"]
172188

173189
# The generated headers, per architecture and per data model.
174190
#

musl/PATCHES.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,25 @@ not know that a program is a kind of file.
138138
`fork` is absent and stays absent. Duplicating a running image is not something
139139
every environment can produce. `posix_spawn`, and therefore `system` and
140140
`popen`, are supplied, because musl builds them on starting a program.
141+
142+
### The fifteen indirect symbols
143+
144+
Where the definition a second name is made for is in the same translation unit,
145+
the assembler's directive produces an ordinary symbol at that address. Where it
146+
is not, it produces an *indirect* symbol, which is the other thing that
147+
directive is for and which one linker refuses in as many words: `TODO: support
148+
aliasing to symbols of kind 1`.
149+
150+
The measurement: 1154 of musl's translation units compiled for that system
151+
produce fifteen such symbols between them, and every one is a function declared
152+
in a header and defined in another unit.
153+
154+
```
155+
dladdr, dlopen, __dlsym, __dl_invalid_handle, __libc_exit_fini, malloc,
156+
pthread_detach, pthread_equal, pthread_getspecific, pthread_tryjoin_np,
157+
thrd_detach, thrd_equal, tss_get, utmpname, utmpxname
158+
```
159+
160+
The response is one flag on the link line rather than fifteen exceptions in a
161+
macro: the link names that system's own linker, which is the one its object
162+
format was designed alongside and which resolves an indirect symbol.

0 commit comments

Comments
 (0)