diff --git a/src/application/releaseExposure/ReleaseExposureService.test.ts b/src/application/releaseExposure/ReleaseExposureService.test.ts index 764c5b22f2..1cfac306d6 100644 --- a/src/application/releaseExposure/ReleaseExposureService.test.ts +++ b/src/application/releaseExposure/ReleaseExposureService.test.ts @@ -2239,6 +2239,32 @@ describe("ReleaseExposureService compiler path separators", () => { ); }); +describe("ReleaseExposureService compiler profile paths", () => { + it.each([ + ["CGO_CFLAGS", "-O2 -fprofile-use=internal/profiles", "internal/profiles"], + ["CGO_CFLAGS", "'-fprofile-dir=private profiles'", "private profiles"], + ["-ldflags", "-extldflags=-fprofile-generate=private/gcov", "private/gcov"], + ])("reports the named directory in %s %s", async (key, value, path) => { + const report = await goReport(goModule([{ key, value }])); + const check = report.checks.find((item) => item.id === "go.build_paths"); + expect(check?.status).toBe("exposed"); + expect(check?.observation.samples).toEqual([path]); + }); + + it("finds no profile path for options without directory operands", async () => { + const report = await goReport( + goModule([ + { + key: "CGO_CFLAGS", + value: "-fprofile-use -fprofile-generate -O2", + }, + ]), + ); + const check = report.checks.find((item) => item.id === "go.build_paths"); + expect(check?.status).toBe("not_observed"); + }); +}); + describe("ReleaseExposureService Go linker -r search list", () => { it.each([["-r=$ORIGIN/../lib -s -w"], ["-r ${ORIGIN}/lib:$ORIGIN"]])( "does not read the ELF loader-expanded entries in %s as build paths", diff --git a/src/domain/releaseExposureGoPaths.ts b/src/domain/releaseExposureGoPaths.ts index 2fafe6645d..55ee3c876f 100644 --- a/src/domain/releaseExposureGoPaths.ts +++ b/src/domain/releaseExposureGoPaths.ts @@ -38,11 +38,13 @@ const GO_FLAG_PATH = * Go's own tools reuse those letters: `-ldflags` takes `-B gobuildid` and * `-T 0x1000`, so their relative arguments are not paths. The exact field * `-I-` is GCC's include barrier, the same as `--include-barrier`, and names - * no directory. + * no directory. GCC profile directory options name a path in their explicit + * equals form. The bare profile-use and profile-generate switches take no + * following operand. */ const GO_COMPILER_SETTING = /^(?:CGO_[A-Z]+FLAGS|-gccgoflags)$/u; const GO_COMPILER_PATH_FLAG = - /^(?:-(?:idirafter|imacros|include|iprefix|iquote|isysroot|isystem|[BFLT]|I(?!-$))=?\s*|--sysroot(?:=|\s+|$))(.*)$/su; + /^(?:-(?:idirafter|imacros|include|iprefix|iquote|isysroot|isystem|[BFLT]|I(?!-$))=?\s*|--sysroot(?:=|\s+|$)|-fprofile-(?:dir|generate|use)=)(.*)$/su; /** * Linker options a C compiler forwards through `-Wl,a,b` or `-Xlinker a`. The * linker reads its own letters: `-L`, `-T` and `-I` (the ELF interpreter) take