On Thursday, December 18, 2025 at 6:03:20 PM UTC-7 [email protected] wrote:

 In 16 years of Go's existence, neither Google nor the community has solved 
                                                                            
                                                                         
  the race detection problem without CGO. ThreadSanitizer requires 
CGO_ENABLED=1,                                                             
                                                                            
        
  which makes it unusable for Docker scratch images, cloud functions,       
                                                                            
                                                                          
  cross-compilation, and embedded systems.                                  
                                                                            
                                                                          


 You can use race detection with scratch images if you include the required 
libraries. Example:

*$ cat hello.go*
package main

import "fmt"

func main() {
        fmt.Println("Hello World")
}

*$ CGO_ENABLED=1 go build -race .*

*$ ldd ./hello | tr -s [:blank:] '\n' | grep ^/ | xargs -I % install -D % 
./%*

*$ tree*
.
├── Dockerfile
├── go.mod
├── hello
├── hello.go
├── lib
│   └── x86_64-linux-gnu
│       └── libc.so.6
└── lib64
    └── ld-linux-x86-64.so.2

3 directories, 6 files

*$ cat Dockerfile*
FROM scratch

COPY li[b] /lib
COPY lib64 /lib64
COPY hello /usr/bin/hello

ENTRYPOINT ["/usr/bin/hello"]

*$ docker build -t hello:latest -f Dockerfile .*
...
...
 => => naming to docker.io/library/hello:latest            0.0s

*$ dive --json /dev/stdout hello:latest | grep path*
          "path": "lib/x86_64-linux-gnu/libc.so.6",
          "path": "lib/x86_64-linux-gnu",
          "path": "lib",
          "path": "lib64/ld-linux-x86-64.so.2",
          "path": "lib64",
          "path": "usr/bin/hello",
          "path": "usr/bin",
          "path": "usr",

*$ docker run --rm hello:latest*
Hello World

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/96e4aa07-3bd5-464a-8d32-1e54172147bfn%40googlegroups.com.

Reply via email to