Skip to contentSkip to conversation

rules.mak: Use -r instead of -Wl, -r to fix building when PIE is default

PATCH In review Adrian Bunk 3 participants 8 messages Nov 27, 2016 – Nov 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rules.mak: Use -r instead of -Wl, -r to fix building when PIE is default

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

---
 rules.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rules.mak +1 -1
index 0333ae3..545ebd9 100644
@@ -93,7 +93,7 @@ module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
 	$(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@),"CP","$(subst /,-,$@)"))
 
 
-LD_REL := $(CC) -nostdlib -Wl,-r $(LD_REL_FLAGS)
+LD_REL := $(CC) -nostdlib -r $(LD_REL_FLAGS)
 
 %.mo:
 	$(call quiet-command,$(LD_REL) -o $@ $^,"LD","$(TARGET_DIR)$@")
Signature · 1 line
2.10.2
#1 lore raw
Quoted 11 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

But the patch would probably remove the need for LD_REL_FLAGS, based on a quick look at the GCC source code, so I guess it's fine.

Paolo

Quoted 18 lines
---
 rules.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rules.mak +1 -1
index 0333ae3..545ebd9 100644
@@ -93,7 +93,7 @@ module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
 	$(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@),"CP","$(subst /,-,$@)"))
 
 
-LD_REL := $(CC) -nostdlib -Wl,-r $(LD_REL_FLAGS)
+LD_REL := $(CC) -nostdlib -r $(LD_REL_FLAGS)
 
 %.mo:
 	$(call quiet-command,$(LD_REL) -o $@ $^,"LD","$(TARGET_DIR)$@")
#2 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Quoted 8 lines
Quoted 4 lines

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

The linker knows nothing about this default, gcc is passing -pie to the linker.

Quoted 3 lines

...
Paolo
...

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw
Quoted 14 lines · Adrian Bunk
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

The linker knows nothing about this default, gcc is passing -pie to the linker.

The linker is receiving "-r -pie". It can satisfy the requirement of producing a relocatable object by discarding the "-r", but it doesn't. That'd be a linker bug.

But in fact ELF makes PIE ET_DYN and relocatable ET_REL. That would make the linker error the right thing, but then I don't understand what you mean by "position independent is already relocatable".

Paolo

#4 lore raw
Quoted 26 lines · Paolo Bonzini
Quoted 14 lines · Adrian Bunk
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

The linker knows nothing about this default, gcc is passing -pie to the linker.

Quoted 7 lines

The linker is receiving "-r -pie". It can satisfy the requirement of producing a relocatable object by discarding the "-r", but it doesn't. That'd be a linker bug.

But in fact ELF makes PIE ET_DYN and relocatable ET_REL. That would make the linker error the right thing, but then I don't understand what you mean by "position independent is already relocatable".

Aha, I looked at GCC source code and this is incorrect: "Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled". When GCC sees -r (as opposed to -Wl,-r) it does not pass -pie to the linker.

Paolo

#5 lore raw
Quoted 4 lines · Paolo Bonzini

Aha, I looked at GCC source code and this is incorrect: "Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled". When GCC sees -r (as opposed to -Wl,-r) it does not pass -pie to the linker.

That's what I get for writing things I did not double-check myself...

You are correct here (with the implication that my patch does change behaviour even less).

Quoted 1 line

Paolo

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#6 lore raw
In reply to Paolo Bonzini
Quoted 33 lines · Paolo Bonzini
Quoted 30 lines · Paolo Bonzini
Quoted 14 lines · Adrian Bunk
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

The linker knows nothing about this default, gcc is passing -pie to the linker.

The linker is receiving "-r -pie". It can satisfy the requirement of producing a relocatable object by discarding the "-r", but it doesn't. That'd be a linker bug.

Quoted 7 lines
Quoted 3 lines

But in fact ELF makes PIE ET_DYN and relocatable ET_REL. That would make the linker error the right thing, but then I don't understand what you mean by "position independent is already relocatable".

Aha, I looked at GCC source code and this is incorrect: "Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled". When GCC sees -r (as opposed to -Wl,-r) it does not pass -pie to the linker.

Should we merge this patch for 2.8 with the commit updated to reflect this?

Stefan

#7 lore raw
Quoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Paolo Bonzini
Quoted 33 lines · Paolo Bonzini
Quoted 14 lines · Adrian Bunk
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Adrian Bunk

Building qemu fails in distributions where gcc enables PIE by default (e.g. Debian unstable) with:
/usr/bin/ld: -r and -pie may not be used together

-r and -pie cannot be used together in the linker, and position independent is already relocatable.

Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think this is a bug in the linker. If the linker is producing relocatable objects by default, it has no reason to refuse -r. Have you tried asking the binutils folks about it too?

The linker knows nothing about this default, gcc is passing -pie to the linker.

The linker is receiving "-r -pie". It can satisfy the requirement of producing a relocatable object by discarding the "-r", but it doesn't. That'd be a linker bug.

But in fact ELF makes PIE ET_DYN and relocatable ET_REL. That would make the linker error the right thing, but then I don't understand what you mean by "position independent is already relocatable".

Quoted 5 lines
Quoted 3 lines

Aha, I looked at GCC source code and this is incorrect: "Use -r instead of -Wl,-r to avoid gcc passing -r to the linker when PIE is enabled". When GCC sees -r (as opposed to -Wl,-r) it does not pass -pie to the linker.

Should we merge this patch for 2.8 with the commit updated to reflect this?

Yes, I've already sent a pull request for it.

Paolo