@@ -26,14 +26,9 @@ import (
2626// Kept minimal and additive so call sites can default-zero fields they
2727// don't need. ltoMode is "thin" or "" (no LTO).
2828type compileIROpts struct {
29- optLevel string // -O0/-O1/-O2/-O3
30- ltoMode string // "thin" or ""
31- debug bool
32- functionSecs bool // -ffunction-sections
33- dataSecs bool // -fdata-sections
34- noUnwindTables bool // -fno-unwind-tables -fno-asynchronous-unwind-tables
35- gLineTablesOnly bool // -gline-tables-only (stacktrace path)
36- targetFlags []string
29+ optLevel string // -O0/-O1/-O2/-O3
30+ ltoMode string // "thin" or ""
31+ targetFlags []string
3732}
3833
3934type linkOpts struct {
@@ -43,8 +38,8 @@ type linkOpts struct {
4338 standaloneDebugMacOS bool
4439 functionSecs bool
4540 dataSecs bool
46- gcSections bool // -Wl,--gc-sections / -Wl,-dead_strip
47- useLld bool // -fuse-ld=lld (cross-compile)
41+ gcSections bool // -Wl,--gc-sections / -Wl,-dead_strip
42+ useLld bool // -fuse-ld=lld (cross-compile)
4843 rdynamic bool
4944 targetGOOS string
5045 targetFlags []string
@@ -131,7 +126,7 @@ func linkBinary(inputs []string, outBin string, opts linkOpts) error {
131126
132127 prefix := entry .prefix
133128 if opts .targetGOOS != "darwin" {
134- prefix = forceBuildIdSha1 (prefix )
129+ prefix = forceBuildIDSha1 (prefix )
135130 }
136131
137132 argv := append ([]string {}, prefix ... )
@@ -155,11 +150,11 @@ func linkBinary(inputs []string, outBin string, opts linkOpts) error {
155150 return nil
156151}
157152
158- // forceBuildIdSha1 rewrites any `--build-id` (default: timestamp hash)
153+ // forceBuildIDSha1 rewrites any `--build-id` (default: timestamp hash)
159154// into `--build-id=sha1` so the note is content-derived and stable
160155// across rebuilds. Leaves an explicit `--build-id=...` choice alone.
161156// ELF-only -- callers skip this on Mach-O.
162- func forceBuildIdSha1 (args []string ) []string {
157+ func forceBuildIDSha1 (args []string ) []string {
163158 out := make ([]string , 0 , len (args ))
164159 for _ , a := range args {
165160 if a == "--build-id" {
@@ -216,34 +211,42 @@ func lldArgvFor(opts linkOpts) *lldArgvEntry {
216211 useLld : opts .useLld ,
217212 }
218213
219- lldArgvCacheMu .Lock ()
220- entry , ok := lldArgvCache [key ]
221- lldArgvCacheMu .Unlock ()
222-
223- if ok {
214+ if entry , ok := lookupLldArgv (key ); ok {
224215 return entry
225216 }
226217
227218 if disk := readLldArgvFromDisk (key ); disk != nil {
228- lldArgvCacheMu .Lock ()
229- lldArgvCache [key ] = disk
230- lldArgvCacheMu .Unlock ()
219+ storeLldArgv (key , disk )
231220
232221 return disk
233222 }
234223
235- entry = probeLldArgv (opts )
224+ entry : = probeLldArgv (opts )
236225 if entry .err == nil {
237226 writeLldArgvToDisk (key , entry )
238227 }
239228
240- lldArgvCacheMu .Lock ()
241- lldArgvCache [key ] = entry
242- lldArgvCacheMu .Unlock ()
229+ storeLldArgv (key , entry )
243230
244231 return entry
245232}
246233
234+ func lookupLldArgv (key lldArgvKey ) (* lldArgvEntry , bool ) {
235+ lldArgvCacheMu .Lock ()
236+ defer lldArgvCacheMu .Unlock ()
237+
238+ e , ok := lldArgvCache [key ]
239+
240+ return e , ok
241+ }
242+
243+ func storeLldArgv (key lldArgvKey , entry * lldArgvEntry ) {
244+ lldArgvCacheMu .Lock ()
245+ defer lldArgvCacheMu .Unlock ()
246+
247+ lldArgvCache [key ] = entry
248+ }
249+
247250// lldProbeCacheDir is the on-disk cache root for linker-argv probe
248251// results. Lives under .build/host-info alongside the host clang
249252// metadata so a single `rm -rf .build/host-info` clears every host-
@@ -285,6 +288,7 @@ func readLldArgvFromDisk(k lldArgvKey) *lldArgvEntry {
285288
286289 pf := strings .Split (strings .TrimRight (parts [1 ], "\n " ), "\n " )
287290 sf := strings .Split (strings .TrimRight (parts [2 ], "\n " ), "\n " )
291+
288292 if len (pf ) == 1 && pf [0 ] == "" {
289293 pf = nil
290294 }
@@ -536,7 +540,7 @@ func isClangTempForBase(t, base string) bool {
536540 }
537541
538542 for _ , c := range rest {
539- if ! (( c >= '0' && c <= '9' ) || (c >= 'a' && c <= 'f' ) || (c >= 'A' && c <= 'F' ) ) {
543+ if ( c < '0' || c > '9' ) && (c < 'a' || c > 'f' ) && (c < 'A' || c > 'F' ) {
540544 return false
541545 }
542546 }
0 commit comments