Menu

#52 Failure to analyze when the symbol table is disabled on darwin/arm64/go 1.22/cgo

open
nobody
bug (3)
2024-06-12
2024-05-21
Anonymous
No

Originally created by: nikpivkin

Hi, thanks for this tool!

Steps to reproduce:

  • git clone https://github.com/aquasecurity/trivy.git && cd trivy
  • go build -ldflags "-s" -o trivy ./cmd/trivy/main.go
  • gsa ./trivy --verbose

    :::sh
    level=INFO msg="Parsing binary..."
    level=INFO msg="Parsing binary done"
    level=INFO msg="Finding build info..."
    level=INFO msg="Build info found"
    level=INFO msg="Loading sections..."
    level=INFO msg="Loading sections done"
    level=INFO msg="Loading packages..."
    level=ERROR msg="Fatal error: failed to find runtime.text symbol: moduledata structure not found"

But if I add an environment variable CGO_ENABLED=0 to disable cgo, the analysis runs successfully.

OS: macos m1
Go: 1.22

Discussion

  • Anonymous

    Anonymous - 2024-05-21

    Originally posted by: Zxilly

    Do you compile with the target darwin-arm64? If so this is an known issue.
    https://github.com/Zxilly/go-size-analyzer/blob/master/scripts/skip.txt

     
  • Anonymous

    Anonymous - 2024-05-21

    Originally posted by: Zxilly

    A temporary workaround is to keep the symbol table, and the dwarf can be removed as it didn't be used right now.

     
  • Anonymous

    Anonymous - 2024-05-21

    Originally posted by: nikpivkin

    Yes, the target is darwin-arm64. Why does this work with CGO_ENABLED=0?

     
  • Anonymous

    Anonymous - 2024-05-21

    Originally posted by: Zxilly

    CGO implicitly enables external links, where links are no longer executed by go, but by the linker provided by the operating system. This will change some of the assumptions of go itself.
    Currently this problem only occurs with darwin-arm64 on go 1.22, and I don't use Apple's M-series chips, so it's hard for me to find out exactly what's wrong.

     
  • Anonymous

    Anonymous - 2024-05-21

    Originally posted by: nikpivkin

    I got it, thanks.

     
  • Anonymous

    Anonymous - 2024-05-29

    Originally posted by: nikpivkin

    @Zxilly I can provide dumps if it can help. I've been trying to research this, but I haven't gotten too far.

     
  • Anonymous

    Anonymous - 2024-05-29

    Originally posted by: Zxilly

    It's an error triggered by an upstream library, and I'm sure it's fixable. And I already have some samples I can use to reproduce the error.
    But I'm busy lately. Maybe I'll have time to look at this in a few months.
    You can follow https://github.com/goretk/gore for progress.

     

Log in to post a comment.

MongoDB Logo MongoDB