retina icon indicating copy to clipboard operation
retina copied to clipboard

fix: failed to build binary by make retina-binary

Open nayihz opened this issue 1 year ago • 10 comments

Addresses issue https://github.com/microsoft/retina/issues/128

nayihz avatar Mar 23 '24 13:03 nayihz

@microsoft-github-policy-service agree

nayihz avatar Mar 23 '24 13:03 nayihz

@nayihz while I believe that this fixes the issue, I don't understand why we don't encounter this issue when we build in our container? https://github.com/microsoft/retina/blob/main/controller/Dockerfile.controller#L38

rbtr avatar Mar 25 '24 20:03 rbtr

TIL about //go:build ignore, thanks for the contribution 😄 This looks pretty good to me as-is... I was able to build this with make retina-binary without any additional ENVs (we had previously been setting CGO_ENABLED=0, but this seems better). I did find that there's a few object files left behind from compiling BPF... would you be interested in adding those to .gitignore as well? They are:

  • pkg/plugin/dropreason/kprobe_bpfel_x86.o
  • pkg/plugin/filter/filter_bpfel_x86.o
  • pkg/plugin/packetforward/packetforward_bpfel_x86.o
  • pkg/plugin/packetparser/packetparser_bpfel_x86.o

timraymond avatar Mar 25 '24 20:03 timraymond

@rbtr It's because we set CGO_ENABLED=0 here: https://github.com/microsoft/retina/blob/cf23ecb9a5ed25c787d1f6ec819518749dfb7774/controller/Dockerfile.controller#L30 . The go toolchain skips over its distaste for C here when CGO is disabled: https://github.com/golang/go/blob/e7bdc8819a19f06321d300719224abb2d8567b4a/src/cmd/go/internal/load/pkg.go#L2060-L2063

timraymond avatar Mar 25 '24 21:03 timraymond

@rbtr It's because we set CGO_ENABLED=0 here:

@timraymond We also disable CGO in the Make target to build the binary, though: https://github.com/microsoft/retina/blob/cf23ecb9a5ed25c787d1f6ec819518749dfb7774/Makefile#L148-L149

rbtr avatar Mar 25 '24 21:03 rbtr

Actually if I'm reading your link correctly len(p.CFiles) > 0 && !p.UsesCgo() means that we get this error when CGO is disabled and there are C files present, right? So the unexpected behavior seems to be that in the Dockerfile, CGO remains enabled despite the env var being set, leading to a sort of "false positive" successful build?

rbtr avatar Mar 25 '24 21:03 rbtr

@rbtr It's because we set CGO_ENABLED=0 here:

@timraymond We also disable CGO in the Make target to build the binary, though:

https://github.com/microsoft/retina/blob/cf23ecb9a5ed25c787d1f6ec819518749dfb7774/Makefile#L148-L149

export CGO_ENABLED=0 doesn't seem to take effect in makefile. We can build successfully when we add export CGO_ENABLED=0 before go generate command.

# makefile
retina-binary: ## build the Retina binary
        export CGO_ENABLED=0 && \
	go generate ./... && \
        go build -v -o $(RETINA_BUILD_DIR)/retina$(EXE_EXT) -gcflags="-dwarflocationlists=true" -ldflags "-X main.version=$(TAG) -X main.applicationInsightsID=$(APP_INSIGHTS_ID)" $(RETINA_DIR)/main.go

nayihz avatar Mar 26 '24 01:03 nayihz

Modifed the makefile to enable CGO_ENABLED=0 and omit ".o" files. PTAL.

nayihz avatar Mar 26 '24 01:03 nayihz

I'm afraid we need those .o files:

Error: 10.40 pkg/plugin/filter/filter_bpfel_arm64.go:119:12: pattern filter_bpfel_arm64.o: no matching files found Error: 10.40 pkg/plugin/dropreason/kprobe_bpfel_arm64.go:190:12: pattern kprobe_bpfel_arm64.o: no matching files found Error: 10.40 pkg/plugin/packetforward/packetforward_bpfel_arm64.go:125:12: pattern packetforward_bpfel_arm64.o: no matching files found Error: 10.40 pkg/plugin/packetparser/packetparser_bpfel_arm64.go:159:12: pattern packetparser_bpfel_arm64.o: no matching files found

https://github.com/microsoft/retina/actions/runs/8429451457/job/23089687153?pr=129

rbtr avatar Mar 26 '24 15:03 rbtr

@nayihz can you please sign and sign-off your commits? git commit -S -s --amend --no-edit should do it

rbtr avatar Mar 28 '24 18:03 rbtr

@nayihz can you please sign and sign-off your commits? git commit -S -s --amend --no-edit should do it

Done.

nayihz avatar Apr 02 '24 03:04 nayihz

Sorry @nayihz, you have correctly Signed-off-By in the commit message message, but it looks like you're missing the cryptographic signature on the commit itself.

This Verified in the commits page is what I'm looking for: image

It is a merge requirement that all commits be signed. See #197

rbtr avatar Apr 02 '24 16:04 rbtr

This Verified in the commits page is what I'm looking for:

Done. PTAL.

nayihz avatar Apr 04 '24 08:04 nayihz

looks good, thanks!

rbtr avatar Apr 04 '24 15:04 rbtr