From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14310 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Samuel Holland Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] add support for powerpc/powerpc64 unaligned relocations Date: Sun, 30 Jun 2019 07:39:20 -0500 Message-ID: <20190630123920.40057-1-samuel@sholland.org> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="81094"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Samuel Holland To: musl@lists.openwall.com Original-X-From: musl-return-14326-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jun 30 14:39:37 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hhZ7J-000KzR-JJ for gllmg-musl@m.gmane.org; Sun, 30 Jun 2019 14:39:37 +0200 Original-Received: (qmail 24243 invoked by uid 550); 30 Jun 2019 12:39:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24208 invoked from network); 30 Jun 2019 12:39:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=coiYt5WB+37Fm6m6mLp7h/zCY/ i1vdiWEzEZCkPdX/U=; b=Mm8aDpg+Vq/ltjkhny7vQW4hEmmAWMx7r9GKwXGT/d ScjaTASt0GdVRExpHNDipi/sA5oSZobMPr9s2NZdizQ1eznWwr/pCQsafvXm2dKZ TlGTuc8/VR68VcOxGTbt45FdhunFx5L9J+B2Z5hoHjBCtm/ZFjdIcYHfFTxHtthi vQK2ood5H8g6vLp8j2PDclTkyGmn5vY8/hx8hdWcQgKTMJtwh56zZXxyK1XobH7S 0bnEuPmxYf/o/3bsQQEzha0xe/BSlKbm+esShhoxtulCievqF7gYyHlMlNoy7ZwI m6wRzwbIswXk6Gq37EVbWbJMPDcEYcu1tMcjQUKw7h+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=coiYt5WB+37Fm6m6m Lp7h/zCY/i1vdiWEzEZCkPdX/U=; b=ccXJiCmumfznlSgpHaFjyXXikDVCnwX0c A1HkGOAiY5m2ZtSi9ev9WhrvQsr8CpOZoNN3O2eBX55X6ZH6syxLU7gwCt6eN3vk Hfmz70Iq16z8NO/oL5+E6NVmx2w9UJidzlPqT+t8pBagRXPTp96lUohXI2EHTB6p fFp8ogal/36TdXh36Y70P3/PQ+3CUtSIQ+Wh1ae02wapUzUYjrSRYxlM8qhdT6Vq aa1XqVpYFxWFaNUgy0RE9mQCPtSYG6UVAfagG6NKEoAl0Ws/3xjVF33JKpRVK0rp IoavbIPSjRWlfByxXRPjNs+zbUmrSD8rBDlHFdRv2KR+vJRCCnEZw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrvdeggdehgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertd dtnecuhfhrohhmpefurghmuhgvlhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhl lhgrnhgurdhorhhgqeenucfkphepjedtrddufeehrddugeekrdduhedunecurfgrrhgrmh epmhgrihhlfhhrohhmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhs thgvrhfuihiivgeptd X-ME-Proxy: X-Mailer: git-send-email 2.21.0 Xref: news.gmane.org gmane.linux.lib.musl.general:14310 Archived-At: R_PPC_UADDR32 (R_PPC64_UADDR64) has the same meaning as R_PPC_ADDR32 (R_PPC64_ADDR64), except that its address need not be aligned. For powerpc64, BFD ld(1) will automatically convert between ADDR<->UADDR relocations when the address is/isn't at its native alignment. This will happen if, for example, there is a pointer in a packed struct. gold and lld do not currently generate R_PPC64_UADDR64, but pass through misaligned R_PPC64_ADDR64 relocations from object files, possibly relaxing them to misaligned R_PPC64_RELATIVE. In both cases (relaxed or not) this violates the PSABI, which defines the relevant field type as "a 64-bit field occupying 8 bytes, the alignment of which is 8 bytes unless otherwise specified." All three linkers violate the PSABI on 32-bit powerpc, where the only difference is that the field is 32 bits wide, aligned to 4 bytes. Currently musl fails to load executables linked by BFD ld containing R_PPC64_UADDR64, with the error "unsupported relocation type 43". This change provides compatibility with BFD ld on powerpc64, and any static linker on either architecture that starts following the PSABI more closely. --- arch/powerpc/reloc.h | 1 + arch/powerpc64/reloc.h | 1 + ldso/dynlink.c | 3 +++ src/internal/dynlink.h | 1 + 4 files changed, 6 insertions(+) diff --git a/arch/powerpc/reloc.h b/arch/powerpc/reloc.h index 1b4cab36..527b6b7c 100644 --- a/arch/powerpc/reloc.h +++ b/arch/powerpc/reloc.h @@ -9,6 +9,7 @@ #define TPOFF_K (-0x7000) #define REL_SYMBOLIC R_PPC_ADDR32 +#define REL_USYMBOLIC R_PPC_UADDR32 #define REL_GOT R_PPC_GLOB_DAT #define REL_PLT R_PPC_JMP_SLOT #define REL_RELATIVE R_PPC_RELATIVE diff --git a/arch/powerpc64/reloc.h b/arch/powerpc64/reloc.h index faf70acd..5bdaeede 100644 --- a/arch/powerpc64/reloc.h +++ b/arch/powerpc64/reloc.h @@ -11,6 +11,7 @@ #define TPOFF_K (-0x7000) #define REL_SYMBOLIC R_PPC64_ADDR64 +#define REL_USYMBOLIC R_PPC64_UADDR64 #define REL_GOT R_PPC64_GLOB_DAT #define REL_PLT R_PPC64_JMP_SLOT #define REL_RELATIVE R_PPC64_RELATIVE diff --git a/ldso/dynlink.c b/ldso/dynlink.c index db543c19..b5ef4bfc 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -407,6 +407,9 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri case REL_PLT: *reloc_addr = sym_val + addend; break; + case REL_USYMBOLIC: + memcpy(reloc_addr, &(size_t){sym_val + addend}, sizeof(size_t)); + break; case REL_RELATIVE: *reloc_addr = (size_t)base + addend; break; diff --git a/src/internal/dynlink.h b/src/internal/dynlink.h index 165bbedb..ffd06b04 100644 --- a/src/internal/dynlink.h +++ b/src/internal/dynlink.h @@ -28,6 +28,7 @@ typedef Elf64_Sym Sym; enum { REL_NONE = 0, REL_SYMBOLIC = -100, + REL_USYMBOLIC, REL_GOT, REL_PLT, REL_RELATIVE, -- 2.21.0