From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99598 invoked by alias); 20 Feb 2020 13:11:45 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 99590 invoked by uid 89); 20 Feb 2020 13:11:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*Ad:U*nickc X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Feb 2020 13:11:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582204301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=nuv0JeM7Ce7sQeKkiJsfVujuZ2svNt3gRaQeqvddFzo=; b=iNMmOswiUYEuuqkaYAhKdz5NIqu04HOPeBJPyoJk/fBqumnOXujp3B/1fW30QGLedLBoMM HC1lncZ6xBthEPyOMDMdkD89d/X3GkcOmBMn6jT2D9XDcchOCRvyiBUJ8UD/CEcVJOoSNn kFT4m3EX7tMPEh/HRYsHsgE+vlYd6Bs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-Q5cnQp27PXOxuLQ3vuHwOg-1; Thu, 20 Feb 2020 08:11:37 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DD75800D48; Thu, 20 Feb 2020 13:11:36 +0000 (UTC) Received: from [10.36.117.133] (ovpn-117-133.ams2.redhat.com [10.36.117.133]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 716C5196AE; Thu, 20 Feb 2020 13:11:35 +0000 (UTC) Subject: Re: RFC: Supporting multiple relocs per section To: Alan Modra Cc: binutils@sourceware.org References: <877e0pmpew.fsf@redhat.com> <20200218002019.GD5570@bubble.grove.modra.org> From: Nick Clifton Message-ID: Date: Thu, 20 Feb 2020 13:11:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200218002019.GD5570@bubble.grove.modra.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------F7D8F1FEB79DB71112A60DAB" X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00498.txt.bz2 This is a multi-part message in MIME format. --------------F7D8F1FEB79DB71112A60DAB Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-length: 1055 Hi Alan, > On Fri, Feb 14, 2020 at 10:30:47AM +0000, Nick Clifton wrote: >> As part of this process I also discovered that the BFD library would >> unconditionally convert OS-specific and PROC-specific section indices >> into SHN_ABS indices when writing out symbol tables, > That sounds like a bug that should be fixed for all ELF targets and > not via a target hook. I have checked in this patch to resolve this particular problem. I do not think that the code has to worry about the sign extension of the special values as this has been handled by the definitions in elf/internal.h. Cheers Nick bfd/ChangeLog 2020-02-20 Nick Clifton * elf-bfd.h (struct elf_backend_data): Add symbol_section_index callback. * elfxx-target.h (elf_backend_symbol_section_index): Provide default definition. (elfNN_bed): Initialise the symbol_section_index field. * elf.c (swap_out_syms): Call symbol_section_index, if defined, on OS and PROC specific section indicies. Warn if converting other reserved incidies to SHN_ABS. --------------F7D8F1FEB79DB71112A60DAB Content-Type: text/x-patch; charset=UTF-8; name="symbol_section_index.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="symbol_section_index.patch" Content-length: 2318 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index cbbba153f4..7d36e23ea1 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1503,6 +1503,12 @@ struct elf_backend_data /* Opcode representing no unwind. */ int (*cant_unwind_opcode) (struct bfd_link_info *); + /* Called when emitting an ELF symbol whoes input version had an + ST_SHNDX field set to a value in the range SHN_LOPROC..SHN_HIOS. + Returns the value to be installed in the ST_SHNDX field of the + emitted symbol. If not defined, the value is left unchanged. */ + unsigned int (*symbol_section_index) (bfd *, elf_symbol_type *); + /* This is non-zero if static TLS segments require a special alignment. */ unsigned static_tls_alignment; diff --git a/bfd/elf.c b/bfd/elf.c index deb93b0a5a..4342e84752 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -8194,9 +8194,26 @@ swap_out_syms (bfd *abfd, if (elf_symtab_shndx_list (abfd)) shndx = elf_symtab_shndx_list (abfd)->ndx; break; - default: + case SHN_COMMON: + case SHN_ABS: shndx = SHN_ABS; break; + default: + if (shndx >= SHN_LOPROC && shndx <= SHN_HIOS) + { + if (bed->symbol_section_index) + shndx = bed->symbol_section_index (abfd, type_ptr); + /* Otherwise just leave the index alone. */ + } + else + { + if (shndx > SHN_HIOS && shndx < SHN_HIRESERVE) + _bfd_error_handler (_("%pB: \ +Unable to handle section index %x in ELF symbol. Using ABS instead."), + abfd, shndx); + shndx = SHN_ABS; + } + break; } } else diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index caca83f5c9..e9cac0a535 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -769,6 +769,10 @@ #define elf_backend_cant_unwind_opcode 0 #endif +#ifndef elf_backend_symbol_section_index +#define elf_backend_symbol_section_index NULL +#endif + #ifndef elf_match_priority #define elf_match_priority \ (ELF_ARCH == bfd_arch_unknown ? 2 : ELF_OSABI == ELFOSABI_NONE ? 1 : 0) @@ -895,6 +899,7 @@ static struct elf_backend_data elfNN_bed = elf_backend_fixup_gnu_properties, elf_backend_compact_eh_encoding, elf_backend_cant_unwind_opcode, + elf_backend_symbol_section_index, elf_backend_static_tls_alignment, elf_backend_stack_align, elf_backend_strtab_flags, --------------F7D8F1FEB79DB71112A60DAB--