vladimirvivien / ktop

A top-like tool for your Kubernetes clusters
Apache License 2.0
747 stars 16 forks source link

Error when building on Linux: 'utf-8' codec can't decode byte 0xc2 in position 6583: invalid continuation byte #8

Closed johanneskastl closed 2 years ago

johanneskastl commented 2 years ago

Hi,

when building this package as an RPM on openSUSE, I get the following error:

[  183s] ktop.x86_64: E: readelf-failed /usr/bin/ktop 'utf-8' codec can't decode byte 0xc2 in position 6583: invalid continuation byte
[  183s] Executing readelf on this file failed, all checks could not be run.

Any idea how to fix that? Is this something that needs to be done inside the source code or am I missing some flags for the build command? (Sorry, golang-Newbie here...)

vladimirvivien commented 2 years ago

Hi @johanneskastl Thanks for the issue. At first glance I have no idea what's going on with what you reported. Can you provide step-by-step detail how you got the error? How were you building the code ?

johanneskastl commented 2 years ago

Hi, basically I just setup a package in the openSUSE Buildservice (OBS) that does all the nitty gritty details: https://build.opensuse.org/package/show/home:ojkastl_buildservice:Branch_devel_kubic/ktop

(OBS spawns a new VM with the desired OS, installs all package dependencies and builds the package inside that VM. This guarantees a clean state every time)

The build step is just:

go build \
   -mod=vendor \
   -buildmode=pie \
   -ldflags="-X main.Version=%{version}"

I also tried without those options but got the same error.

BTW, this build is using go1.17, but I get the same error with go1.16.

vladimirvivien commented 2 years ago

@johanneskastl I don't usually build with buildmode=pie, so I am not familiar of its requirements. My suggestion is to remove it (or use buildmode=default), so that the build generates a native executable for the targeted OS/architecture.

johanneskastl commented 2 years ago

Hi Vladimir, removing this options does not help, as I wrote. I still get the error when omitting this parameter.

vladimirvivien commented 2 years ago

@johanneskastl Since I am not entirely sure how your build env is setup, I can only guess (based on error below) it is building a binary for the wrong OS/arc combination. The second line in error, readelf failed indicates there is an ELF problem which means that the binary that was built cant run on the OS/arc combination where the package is being prepared.

[  183s] ktop.x86_64: E: readelf-failed /usr/bin/ktop 'utf-8' codec can't decode byte 0xc2 in position 6583: invalid continuation byte
[  183s] Executing readelf on this file failed, all checks could not be run.

I think the error is happening at this line in your rpm spec:

# Install the binary.
install -D -m 0755 %{name} "%{buildroot}/%{_bindir}/%{name}"

Suggestions

I am not an expert in RPM building. But I can only suggest some simple debugging steps:

  1. Do a local build (outside of OBS) to make sure you can build the code (which I am guessing is not the problem)
  2. Use OBS to do a simple build that targets one arc only (i.e. x86_64 for example) , then test to see if your spec succeeds
  3. If you are building for Linux/x86_64 only, try specifying that in your build
GOOS=linux GOARCH=amd64 go build \
   -mod=vendor \
   -buildmode=pie \
   -ldflags="-X main.Version=%{version}"```

Hope this helps move your effort further. Thanks for doing this.

johanneskastl commented 2 years ago

I just did some more testing:

So I asked for help on the opensuse-go mailing list. I'll let you know if there is any answer or solution.

Thanks for your help, Vladimir!

johanneskastl commented 2 years ago

This seems to be unrelated to this exact package, I saw this also on other packages. Seems to be an error inside the actual rpmlint check.

Hence closing this issue.