Skip to contentSkip to conversation

pc-bios/s390-ccw: link statically

PATCH In review Sertonix 3 participants 6 messages Jun 10, 2025 – Jun 13, 2025

lore
Share & tools
lore

Sertonix

author
#0 lore raw

PATCH 1/1 pc-bios/s390-ccw: link statically

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked. By using -static-pie it will be linked statically like other bios.

This ensures that the build output doesn't change depending on the default dynamic loader path of the toolchain.

Ref d884c86dcd3b s390/bios: Make the s390-ccw.img relocatable

---
 pc-bios/s390-ccw/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/Makefile +1 -1
index dc69dd484f..a0f24c94a8 100644
@@ -47,7 +47,7 @@ EXTRA_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
 EXTRA_CFLAGS += -msoft-float
 EXTRA_CFLAGS += -std=gnu99
 EXTRA_CFLAGS += $(LIBC_INC) $(LIBNET_INC)
-EXTRA_LDFLAGS += -Wl,-pie -nostdlib -z noexecstack -z text
+EXTRA_LDFLAGS += -static-pie -nostdlib -z noexecstack -z text
 
 cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>/dev/null
 cc-option = if $(call cc-test, $1); then \
Signature · 1 line
2.49.0
#1 lore raw
Quoted 2 lines · Sertonix

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked.

Why do you think -pie causes it to become dynamically linked?

/mjt

author
#2 lore raw
Quoted 7 lines · Michael Tokarev
Quoted 2 lines · Sertonix

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked.

Why do you think -pie causes it to become dynamically linked?

/mjt

The documentation (at least for gcc) states that the -pie option produces a *dynamically* linked position independent executable. (And I verified that the patch changes the resulting binary from dynamically linked to statically linked).

Ref https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-pie

#3 lore raw
Quoted 5 lines · Sertonix
Quoted 4 lines · Michael Tokarev
Quoted 2 lines · Sertonix

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked.

Quoted 8 lines
Quoted 3 lines

Why do you think -pie causes it to become dynamically linked?

/mjt

The documentation (at least for gcc) states that the -pie option produces a *dynamically* linked position independent executable. (And I verified that the patch changes the resulting binary from dynamically linked to statically linked).

Ok.

Why I asked is because -pie by its own does not change "dynaminess" of an executable.

-pie has been introduced for s390-ccw in commit d884c86dcd "s390/bios:
Make the s390-ccw.img relocatable" (9 Mar 2015). Before this commit, s390x-ccw.img has been dynamically linked too. Now with current master (commit bc98ffdc75), removing -Wl,-fpie from LDFLAGS does not change the fact that the image is linked dynamically.

I don't know when s390-ccw.img has become a dynamic executable, maybe it always has been - I haven't looked at earlier commits. With this, I've no idea how it works either, as a dynamic executable with an interpreter etc. But it's definitely not -pie added to LDFLAGS which made it dynamically linked.

On the other hand, people sometimes confuse the result of -static-pie as a dynamic executable, especially with older file(1) utility which reported it as dynamically linked.

So my question was badly worded: what I wanted to ask is what makes you think that adding -pie to the link line makes the resulting executable to be linked dynamically.

With all the above in mind, I think the commit message is misleading a bit. But it'd be interesting to clarify how this image, being a dynamic executable, worked all these years, and why it has to be changed now. I'm definitely not opposing to the change, I just am curious about this aspect and want a correct commit message.

Thanks,

/mjt

author
#4 lore raw
Quoted 15 lines · Michael Tokarev
Quoted 5 lines · Sertonix
Quoted 4 lines · Michael Tokarev
Quoted 2 lines · Sertonix

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked.

Quoted 8 lines
Quoted 3 lines

Why do you think -pie causes it to become dynamically linked?

/mjt

The documentation (at least for gcc) states that the -pie option produces a *dynamically* linked position independent executable. (And I verified that the patch changes the resulting binary from dynamically linked to statically linked).

Quoted 4 lines

Ok.

Why I asked is because -pie by its own does not change "dynaminess" of an executable.

I am uncertain what you mean with "dynaminess" but I mean the ELF file type, whether or not an interpreter is set and some additional sections (like .dynamic) exist.

Quoted 5 lines

-pie has been introduced for s390-ccw in commit d884c86dcd "s390/bios:
Make the s390-ccw.img relocatable" (9 Mar 2015). Before this commit, s390x-ccw.img has been dynamically linked too. Now with current master (commit bc98ffdc75), removing -Wl,-fpie from LDFLAGS does not change the fact that the image is linked dynamically.

The prebuild binary before d884c86dcd was added in 553ce81c31e4 and shows as statically linked: (ET_EXEC is the ELF file type of static binaries)

~/src/qemu$ scanelf pc-bios/s390-ccw.img
TYPE FILE
ET_EXEC pc-bios/s390-ccw.img

and when the binary was rebuild after d884c86dcd in 2d5eeef1c0be it shows as dynamically linked:

~/src/qemu$ scanelf pc-bios/s390-ccw.img
TYPE FILE
ET_DYN pc-bios/s390-ccw.img

(Same results with file(1) and readelf -l)

Quoted 3 lines

On the other hand, people sometimes confuse the result of -static-pie as a dynamic executable, especially with older file(1) utility which reported it as dynamically linked.

Latest file(1) release:

$ file --version
file-5.46
magic file from /usr/share/misc/magic
Quoted 8 lines

So my question was badly worded: what I wanted to ask is what makes you think that adding -pie to the link line makes the resulting executable to be linked dynamically.

With all the above in mind, I think the commit message is misleading a bit. But it'd be interesting to clarify how this image, being a dynamic executable, worked all these years, and why it has to be changed now.

As mentioned above this is only about the file metadata and doesn't affect the binary code part of the binary. So it is probably just ignored by qemu and shouldn't change the bhaviour of qemu. This is mostly to fix the intend of the commit that added -pie and exclude a libc dependant string from a binary that isn't libc dependant.

Quoted 6 lines

I'm definitely not opposing to the change, I just am curious about this aspect and want a correct commit message.

Thanks,

/mjt

#5 lore raw
Quoted 38 lines · Sertonix
Quoted 15 lines · Michael Tokarev
Quoted 5 lines · Sertonix
Quoted 4 lines · Michael Tokarev
Quoted 2 lines · Sertonix

Adding -pie to LDFLAGS caused s390-ccw.img to become dynamically linked.

Quoted 8 lines
Quoted 3 lines

Why do you think -pie causes it to become dynamically linked?

/mjt

The documentation (at least for gcc) states that the -pie option produces a *dynamically* linked position independent executable. (And I verified that the patch changes the resulting binary from dynamically linked to statically linked).

Quoted 4 lines

Ok.

Why I asked is because -pie by its own does not change "dynaminess" of an executable.

I am uncertain what you mean with "dynaminess" but I mean the ELF file type, whether or not an interpreter is set and some additional sections (like .dynamic) exist.

Quoted 5 lines

-pie has been introduced for s390-ccw in commit d884c86dcd "s390/bios:
Make the s390-ccw.img relocatable" (9 Mar 2015). Before this commit, s390x-ccw.img has been dynamically linked too. Now with current master (commit bc98ffdc75), removing -Wl,-fpie from LDFLAGS does not change the fact that the image is linked dynamically.

The prebuild binary before d884c86dcd was added in 553ce81c31e4 and shows as statically linked: (ET_EXEC is the ELF file type of static binaries)

~/src/qemu$ scanelf pc-bios/s390-ccw.img
TYPE FILE
ET_EXEC pc-bios/s390-ccw.img

Quoted 8 lines

and when the binary was rebuild after d884c86dcd in 2d5eeef1c0be it shows as dynamically linked:

~/src/qemu$ scanelf pc-bios/s390-ccw.img
TYPE FILE
ET_DYN pc-bios/s390-ccw.img

(Same results with file(1) and readelf -l)

I was initially also surprised by this (since there was no "-static" flag in the Makefile before the change to "-pie"), but I can also reproduce these results. I didn't find anything related to that in the documentation, but it seems like "-nostdlib" without "-pie" causes the linker to emit a statically linked binary, and with "-pie" it's dynamically instead?

Anyway, this patch here looks fine to me, so I'll queue it for the next time when the s390-ccw.img needs an update (might take a while, though, so please be patient).

Thanks,
Thomas