Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failed to build binary by make retina-binary #129

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

nayihz
Copy link
Contributor

@nayihz nayihz commented Mar 23, 2024

Addresses issue #128

@nayihz nayihz requested a review from a team as a code owner March 23, 2024 13:00
@nayihz
Copy link
Contributor Author

nayihz commented Mar 23, 2024

@microsoft-github-policy-service agree

@rbtr rbtr added the type/fix Fixes something label Mar 25, 2024
@rbtr rbtr added this to the v0.0.2 milestone Mar 25, 2024
@rbtr
Copy link
Collaborator

rbtr commented Mar 25, 2024

@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

@timraymond
Copy link
Member

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
Copy link
Member

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

ENV CGO_ENABLED=0
. 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

@rbtr
Copy link
Collaborator

rbtr commented Mar 25, 2024

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

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

retina/Makefile

Lines 148 to 149 in cf23ecb

export CGO_ENABLED=0
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

@rbtr
Copy link
Collaborator

rbtr commented Mar 25, 2024

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?

@nayihz
Copy link
Contributor Author

nayihz commented Mar 26, 2024

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

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

retina/Makefile

Lines 148 to 149 in cf23ecb

export CGO_ENABLED=0
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

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
Copy link
Contributor Author

nayihz commented Mar 26, 2024

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

@rbtr
Copy link
Collaborator

rbtr commented Mar 26, 2024

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

Copy link
Contributor

@anubhabMajumdar anubhabMajumdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can you please remove the generated object files (not delete them from the repository, just the updated ones from your PR)? I think they don't need to be updated as part of the PR.

@rbtr rbtr removed this from the v0.0.2 milestone Mar 26, 2024
@nayihz nayihz force-pushed the fix-make-retina-binary branch 2 times, most recently from 5beac78 to e663f67 Compare March 27, 2024 01:24
@rbtr rbtr added the priority/0 P0 label Mar 28, 2024
@rbtr
Copy link
Collaborator

rbtr commented Mar 28, 2024

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

@nayihz
Copy link
Contributor Author

nayihz commented Apr 2, 2024

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

Done.

@rbtr rbtr enabled auto-merge April 2, 2024 05:12
@rbtr
Copy link
Collaborator

rbtr commented Apr 2, 2024

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

auto-merge was automatically disabled April 3, 2024 09:46

Head branch was pushed to by a user without write access

@nayihz
Copy link
Contributor Author

nayihz commented Apr 4, 2024

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

Done. PTAL.

@rbtr rbtr enabled auto-merge April 4, 2024 15:12
@rbtr
Copy link
Collaborator

rbtr commented Apr 4, 2024

looks good, thanks!

@rbtr rbtr added this pull request to the merge queue Apr 4, 2024
Merged via the queue into microsoft:main with commit 433bdca Apr 4, 2024
21 checks passed
@nayihz nayihz deleted the fix-make-retina-binary branch April 6, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/0 P0 type/fix Fixes something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants