mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
test(elf): share single-export fixtures (#17322)
This commit is contained in:
1 parent
5cdd0422df
commit
0d425cc445
1 file changed
+7
-22
@@ -1279,6 +1279,9 @@ const nullSymbolNameNote = (nameOffset: number) =>
|
||||
new RegExp(`symbol 0\\b.*0x100\\b.*0x${nameOffset.toString(16)}\\b`, "su"),
|
||||
);
|
||||
|
||||
const singleExportImage = (bits: 32 | 64, little: boolean) =>
|
||||
elfExportImage({ bits, little, symbols: [{ name: "kept_export" }] });
|
||||
|
||||
describe("ELF dynamic symbol null entry", () => {
|
||||
it.each([32, 64] as const)(
|
||||
"rejects an ELF%s null symbol with a nonzero field other than st_name",
|
||||
@@ -1286,21 +1289,13 @@ describe("ELF dynamic symbol null entry", () => {
|
||||
for (const little of [true, false]) {
|
||||
const width = bits === 64 ? 24 : 16;
|
||||
for (let byte = 4; byte < width; byte++) {
|
||||
const bytes = elfExportImage({
|
||||
bits,
|
||||
little,
|
||||
symbols: [{ name: "kept_export" }],
|
||||
});
|
||||
const bytes = singleExportImage(bits, little);
|
||||
bytes[NULL_SYMBOL_OFFSET + byte] = 1;
|
||||
expect(() => parseNativeExports(bytes, artifact)).toThrow(
|
||||
BinaryFormatFailure,
|
||||
);
|
||||
}
|
||||
const named = elfExportImage({
|
||||
bits,
|
||||
little,
|
||||
symbols: [{ name: "kept_export" }],
|
||||
});
|
||||
const named = singleExportImage(bits, little);
|
||||
writeNullSymbolName(named, 0x956, little);
|
||||
named[NULL_SYMBOL_OFFSET + (bits === 64 ? 4 : 12)] = 0x12;
|
||||
expect(() => parseNativeExports(named, artifact)).toThrow(
|
||||
@@ -1317,23 +1312,13 @@ describe("ELF dynamic symbol null entry", () => {
|
||||
"records a nonzero st_name on an otherwise undefined ELF%s symbol",
|
||||
(bits) => {
|
||||
for (const little of [true, false]) {
|
||||
const clean = parse(
|
||||
elfExportImage({
|
||||
bits,
|
||||
little,
|
||||
symbols: [{ name: "kept_export" }],
|
||||
}),
|
||||
);
|
||||
const clean = parse(singleExportImage(bits, little));
|
||||
expect(clean.exports.map(({ name }) => name)).toEqual(["kept_export"]);
|
||||
expect(clean.limitations.join("\n")).not.toContain("st_name");
|
||||
// 0x956 is the reported shape and falls outside this fixture's
|
||||
// string table. Offset 1 is the bytes of kept_export.
|
||||
for (const nameOffset of [0x956, 1]) {
|
||||
const bytes = elfExportImage({
|
||||
bits,
|
||||
little,
|
||||
symbols: [{ name: "kept_export" }],
|
||||
});
|
||||
const bytes = singleExportImage(bits, little);
|
||||
writeNullSymbolName(bytes, nameOffset, little);
|
||||
const result = parse(bytes);
|
||||
expect(result.exports.map(({ name }) => name)).toEqual([
|
||||
|
||||
Reference in new issue
Block a user