-
Notifications
You must be signed in to change notification settings - Fork 47
Closed
Description
Summary
linkMainPkg feeds the linker the raw .o files when a package was just built, but after that package hits the compiler cache we link the cached .a instead. The link step should always consume the archive so cache hits and misses behave identically.
Steps to Reproduce
- Ensure
LLGO_BUILD_CACHE=onand run any build (llgo build ./demo/helloworks) with verbose logging. - On the first build (cache miss) observe that the linker command receives every package's
.ofiles (seelinkMainPkg->objFilesininternal/build/build.go:823-907). - Run the same build again. Because
tryLoadFromCachesetspkg.LLFiles = []string{paths.Archive}(internal/build/collect.go:306-349), the linker now receives.aarchives stored bysaveToCache(internal/build/collect.go:440-493).
Analysis
- Fresh builds call
buildPkg, which only appends.ooutputs (concatPkgLinkFiles,exportObject, etc.) toaPkg.LLFiles(internal/build/build.go:1064-1089). saveToCachealready creates an archive from those.ofiles, but the archive is ignored until the next build whentryLoadFromCacherewritespkg.LLFilesto the.a(internal/build/collect.go:342-349).- Because
linkMainPkgblindly appendsaPkg.LLFiles, the first build links.owhile the next links.a. This means the linker input and ordering changes depending on whether the cache was warm, which is exactly the inconsistency reported in the bug description.
Expected Behavior
Every package should always be linked via its .a archive so cache state does not change the linker inputs.
Actual Behavior
Cache misses link .o files, cache hits link .a. The transition happens purely based on whether pkg.CacheHit was true.
Proposed Fix
Normalize aPkg.LLFiles to the .a archive right after a package is built (or teach linkMainPkg/linkObjFiles to treat .o and .a uniformly) so the linker command line never depends on cache state.
Environment
- commit: ef4877e
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels