Skip to content

Commit 48a7ab5

Browse files
committed
a static image cannot answer dladdr, and that is not a failure
expat's member asserts that the code which parsed is not the ecosystem payload's libexpat, and asks `dladdr` to attribute it. musl's `dladdr` is `weak_alias(stub_dladdr, dladdr)` returning 0 (src/ldso/dladdr.c); the dynamic loader overrides it, and a static link has no loader to do so. An openkal program is statically linked, so the call returns 0 for every address and the member failed one check on both targets. The risk the check exists for cannot arise there either: nothing was loaded at runtime, so the only expat in the process is the one that was linked in. Skipping it would make "no loader" and "the loader answered wrongly" the same reading, so the fallback asserts what distinguishes them. `main` is in this executable by construction; if `dladdr` cannot locate that either, there is no dynamic symbol information at all. If it locates `main` and not `XML_ParserCreate`, the check fails as it did before. Measured both ways: `runs` on both openkal targets, and on a dynamic host build the positive branch still runs and still prints what it resolved.
1 parent e82b320 commit 48a7ab5

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎tests/examples/expat/tests/xml.cpp‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,39 @@ int main()
102102
// the same either way: the code that just parsed must not have come from
103103
// the ecosystem's `xim:expat`, which is present whenever Mesa is and would
104104
// otherwise answer silently.
105+
//
106+
// A STATICALLY LINKED BINARY CANNOT ANSWER THIS, AND THAT IS NOT A
107+
// FAILURE. musl's `dladdr` is `weak_alias(stub_dladdr, dladdr)` returning
108+
// 0 (src/ldso/dladdr.c); the dynamic loader overrides it, and a static
109+
// link has no loader to do so. An openkal program is statically linked, so
110+
// the call returns 0 for every address, and the risk this check exists for
111+
// cannot arise there either: nothing was loaded at runtime, so the only
112+
// expat in the process is the one that was linked in.
113+
//
114+
// SKIPPING IT SILENTLY WOULD MAKE "no loader" AND "the loader answered
115+
// wrongly" THE SAME READING, so the fallback asserts what distinguishes
116+
// them. `main` is in this executable by construction; if `dladdr` cannot
117+
// locate that either, there is no dynamic symbol information at all and
118+
// the question is moot. If it locates `main` but not `XML_ParserCreate`,
119+
// something is wrong and the check fails as before.
105120
{
106121
Dl_info info{};
107122
const bool located =
108123
::dladdr(reinterpret_cast<void *>(&XML_ParserCreate), &info) != 0
109124
&& info.dli_fname != nullptr;
110-
check(located, "dladdr locates the code that parsed");
111125
if (located) {
112126
const std::string from = info.dli_fname;
113127
std::printf(" resolved from: %s\n", from.c_str());
114128
check(from.find("xim-x-expat") == std::string::npos,
115129
"it is not the ecosystem payload's libexpat");
130+
} else {
131+
Dl_info self{};
132+
const bool anyAnswer =
133+
::dladdr(reinterpret_cast<void *>(&main), &self) != 0;
134+
std::printf(" dladdr answers nothing in this image%s\n",
135+
anyAnswer ? " EXCEPT main" : " at all (static link)");
136+
check(!anyAnswer,
137+
"dladdr locates the code that parsed, or locates nothing");
116138
}
117139
}
118140

0 commit comments

Comments
 (0)