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

Can't build with caddy/cache-handler on amd64 #374

Closed
cdaguerre opened this issue Dec 12, 2023 · 4 comments
Closed

Can't build with caddy/cache-handler on amd64 #374

cdaguerre opened this issue Dec 12, 2023 · 4 comments

Comments

@cdaguerre
Copy link

The following Dockerfile can not be built for amd64 target arch, regardless of the underlying host machine.
It works fine for arm64.

FROM dunglas/frankenphp:latest-builder-php8.3-alpine AS builder

COPY --from=caddy:builder-alpine /usr/bin/xcaddy /usr/bin/xcaddy

ENV CGO_ENABLED=1 XCADDY_SETCAP=1
RUN xcaddy build \
    --output /usr/local/bin/frankenphp \
    --with github.com/dunglas/frankenphp=./ \
    --with github.com/dunglas/frankenphp/caddy=./caddy/ \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/vulcain/caddy \
    --with github.com/caddyserver/transform-encoder \
    --with github.com/darkweak/souin/plugins/caddy 	
95.61 2023/12/12 20:31:45 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/local/bin/frankenphp -ldflags -w -s -trimpath 
316.0 # caddy
316.0 /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
316.0 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/go-link-1036742013/000004.o: warning: relocation against `sapi_module' in read-only section `.text'
316.0 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/go-link-1036742013/000004.o: relocation R_X86_64_PC32 against symbol `stderr' can not be used when making a PDE object; recompile with -fPIE
316.0 /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: final link failed: bad value
316.0 collect2: error: ld returned 1 exit status

Things I've already tried :

  • building without souin works
  • building caddy with souin (without frankenphp) works (regardless of CGO)

Any help would be greatly appreciated!

@withinboredom
Copy link
Collaborator

Huh, yeah, that's a weird one. I tried setting:

CGO_CXXFLAGS=-fPIE CGO_CFLAGS=-fPIE CGO_LDFLAGS=-pie

and it didn't seem to make any difference (almost like it is ignoring the flags, however, setting them to obviously wrong values results in an expected error). I tried alpine (musl) and bookworm (libc) and got basically the same result as well.

Maybe I am doing something wrong, or maybe the link error here is from go and not cgo. In which case maybe go build -buildmode=pie will work, but I'm not sure how to get xcaddy to do that.

@cdaguerre
Copy link
Author

Thanks for the tip.
Setting XCADDY_GO_BUILD_FLAGS='-buildmode=pie -ldflags="-w -s" -trimpath' does the trick.

I have no clue whether this is a workaround or an actual solution.
Do you know?

@withinboredom
Copy link
Collaborator

Do you know?

It's a different way of laying out the code in memory, and it should still work fine.

As a side note, I wonder if applying this might mitigate the epic crash when echoing from Fibers (see #46). It probably won't, but I never thought of using position independence to test with, especially since PIE is an x64 thing (IIRC) and we don't really see the crash on Macs (IIRC).

🤔

Please do let us know if you run into any more issues with positional independence turned on though, for now, I'm going to close this.

@cdaguerre
Copy link
Author

thanks @withinboredom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants