Received: from eggs.gnu.org ([2001:4830:134:3::10]:42584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBO66-0005j8-A0 for qemu-devel@nongnu.org; Mon, 28 Nov 2016 10:44:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cBO61-0003hx-7l for qemu-devel@nongnu.org; Mon, 28 Nov 2016 10:44:02 -0500 Sender: Paolo Bonzini References: <20161127162817.15144-1-bunk@stusta.de> <20161128152404.sywmey4pdcv7btup@bunk.spdns.de> <36ee35dd-49ea-f2e3-fa1e-600483b9d4e7@redhat.com> From: Paolo Bonzini Message-ID: <460f994a-fe47-1d1e-0d26-1220d8a05256@redhat.com> Date: Mon, 28 Nov 2016 16:42:54 +0100 MIME-Version: 1.0 In-Reply-To: <36ee35dd-49ea-f2e3-fa1e-600483b9d4e7@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] rules.mak: Use -r instead of -Wl, -r to fix building when PIE is default List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Adrian Bunk Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org On 28/11/2016 16:38, Paolo Bonzini wrote: > > > On 28/11/2016 16:24, Adrian Bunk wrote: >> On Mon, Nov 28, 2016 at 04:05:33PM +0100, Paolo Bonzini wrote: >>> >>> >>> On 27/11/2016 17:28, Adrian Bunk wrote: >>>> 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. >>>> >>>> Signed-off-by: Adrian Bunk >>> >>> 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". 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