From bfc32449bd012796454a7768702452ef79a74c02 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Thu, 29 Oct 2026 02:49:31 -0500 Subject: [PATCH] Check section names only for ELF objects in the never-ran profile test Mach-O and COFF objects keep every function in one text section, so the test compares the objects built with and without the block counts on every target and checks the hot and unlikely sections on ELF targets. --- packages/compiler/test/native-profile.test.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/compiler/test/native-profile.test.ts b/packages/compiler/test/native-profile.test.ts index 6744a0973..7af252657 100644 --- a/packages/compiler/test/native-profile.test.ts +++ b/packages/compiler/test/native-profile.test.ts @@ -190,6 +190,9 @@ function rareExit(argc: number): number { return v & 127; } +/** The target writes ELF objects. */ +const elfTarget = target !== null && !/apple|darwin|windows|mingw/.test(target.llvmTriple); + /** The section that holds `name` in an object file. */ async function sectionOf(object: string, name: string): Promise { const { stdout } = await execFileAsync("objdump", ["-t", object]); @@ -658,16 +661,27 @@ describe.runIf(helper !== null)("LLVM profile-guided optimization", () => { // Without the block counts rare keeps no counts; with them it is cold // code. added, which the block counts do not name, keeps no counts. const [plain] = await emit(dir, rareProgram(), { outputs: 1, name: "plain", use: profile }); + const [marked] = await emit(dir, rareProgram(), { + outputs: 1, + name: "marked", + use: profile, + blocks, + }); + expect(await readFile(marked!)).not.toEqual(await readFile(plain!)); const [cold] = await emit(dir, rareProgram(true), { outputs: 1, name: "cold", use: profile, blocks, }); - expect(await sectionOf(plain!, "rare")).toBe(".text"); - expect(await sectionOf(cold!, "rare")).toMatch(/^\.text\.unlikely/); - expect(await sectionOf(cold!, "added")).toBe(".text"); - expect(await sectionOf(cold!, "hot")).toMatch(/^\.text\.hot/); + // ELF objects name the sections of hot and unlikely code; Mach-O and + // COFF objects keep every function in one text section. + if (elfTarget) { + expect(await sectionOf(plain!, "rare")).toBe(".text"); + expect(await sectionOf(cold!, "rare")).toMatch(/^\.text\.unlikely/); + expect(await sectionOf(cold!, "added")).toBe(".text"); + expect(await sectionOf(cold!, "hot")).toMatch(/^\.text\.hot/); + } expect(await run(await link(dir, [cold!], "cold"), 2)).toBe(rareExit(2)); });