From patchwork Wed Jul 12 16:13:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wang X-Patchwork-Id: 21562 Received: (qmail 49561 invoked by alias); 12 Jul 2017 16:13:52 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 49205 invoked by uid 89); 12 Jul 2017 16:13:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2057, adr X-HELO: foss.arm.com To: libc-alpha@sourceware.org From: Jiong Wang Subject: [ARM] Fix ld.so crash when built using Binutils 2.29 Message-ID: <065a8567-cfca-989b-587b-70584035f529@foss.arm.com> Date: Wed, 12 Jul 2017 17:13:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Hi, There is bug report that ld.so in GLIBC 2.24 built by Binutils 2.29 will crash on arm-linux-gnueabihf. This is confirmed, and the details is at: https://sourceware.org/bugzilla/show_bug.cgi?id=21725. And I could also reproduce this crash using GLIBC master. As analyzed in the PR, the old code was with the assumption that assembler won't set bit0 of thumb function address if it comes from PC-relative instructions and the calculation can be finished during assembling. This assumption however does not hold after PR gas/21458. I think ARM backend in GLIBC should be fix to be more portable so it could work with various combinations of GLIBC and Binutils. OK for master and backport to all release branches? 2017-07-12 Jiong Wang * sysdeps/arm/dl-machine.h (elf_machine_load_address): Also strip bit 0 of pcrel_address under Thumb mode. diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h index 7053ead16ed0e7dac182660f7d88fa21f2b4799a..5b67e3d004818308d9bf93effb13d23a762e160f 100644 --- a/sysdeps/arm/dl-machine.h +++ b/sysdeps/arm/dl-machine.h @@ -56,11 +56,19 @@ elf_machine_load_address (void) extern Elf32_Addr internal_function __dl_start (void *) asm ("_dl_start"); Elf32_Addr got_addr = (Elf32_Addr) &__dl_start; Elf32_Addr pcrel_addr; + asm ("adr %0, _dl_start" : "=r" (pcrel_addr)); #ifdef __thumb__ - /* Clear the low bit of the funciton address. */ + /* Clear the low bit of the funciton address. + + NOTE: got_addr is from GOT table whose lsb is always set by linker if it's + Thumb function address. PCREL_ADDR comes from PC-relative calculation + which will finish during assembling. GAS assembler before the fix for + PR gas/21458 was not setting the lsb but does after that. Always do the + strip for both, so the code works with various combinations of glibc and + Binutils. */ got_addr &= ~(Elf32_Addr) 1; + pcrel_addr &= ~(Elf32_Addr) 1; #endif - asm ("adr %0, _dl_start" : "=r" (pcrel_addr)); return pcrel_addr - got_addr; }