From owner-dev-commits-src-branches@freebsd.org Thu Mar 18 01:25:06 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 79DB25A84AF; Thu, 18 Mar 2021 01:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F18TZ2dFMz3vCf; Thu, 18 Mar 2021 01:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3B13D19293; Thu, 18 Mar 2021 01:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12I1P6AB083582; Thu, 18 Mar 2021 01:25:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12I1P6Od083581; Thu, 18 Mar 2021 01:25:06 GMT (envelope-from git) Date: Thu, 18 Mar 2021 01:25:06 GMT Message-Id: <202103180125.12I1P6Od083581@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e37ad9ef372d - stable/13 - link_elf_obj: Handle init_array sections in KLDs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e37ad9ef372d7e3ff6cdc20ddb9003db116e91ea Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2021 01:25:06 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e37ad9ef372d7e3ff6cdc20ddb9003db116e91ea commit e37ad9ef372d7e3ff6cdc20ddb9003db116e91ea Author: Mark Johnston AuthorDate: 2021-03-04 15:02:47 +0000 Commit: Mark Johnston CommitDate: 2021-03-18 01:24:34 +0000 link_elf_obj: Handle init_array sections in KLDs Reuse existing handling for .ctors, print a warning if multiple constructor sections are present. Destructors are not handled as of yet. This is required for KASAN. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29049 (cherry picked from commit 5e6989ba4f26acafc77baa6055c0a9e7fe683514) --- sys/kern/link_elf_obj.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 6b5a6df0a56f..337588bd5c00 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -386,6 +386,8 @@ link_elf_link_preload(linker_class_t cls, const char *filename, #ifdef __amd64__ case SHT_X86_64_UNWIND: #endif + case SHT_INIT_ARRAY: + case SHT_FINI_ARRAY: /* Ignore sections not loaded by the loader. */ if (shdr[i].sh_addr == 0) break; @@ -470,6 +472,7 @@ link_elf_link_preload(linker_class_t cls, const char *filename, #ifdef __amd64__ case SHT_X86_64_UNWIND: #endif + case SHT_FINI_ARRAY: if (shdr[i].sh_addr == 0) break; ef->progtab[pb].addr = (void *)shdr[i].sh_addr; @@ -479,6 +482,10 @@ link_elf_link_preload(linker_class_t cls, const char *filename, else if (shdr[i].sh_type == SHT_X86_64_UNWIND) ef->progtab[pb].name = "<>"; #endif + else if (shdr[i].sh_type == SHT_INIT_ARRAY) + ef->progtab[pb].name = "<>"; + else if (shdr[i].sh_type == SHT_FINI_ARRAY) + ef->progtab[pb].name = "<>"; else ef->progtab[pb].name = "<>"; ef->progtab[pb].size = shdr[i].sh_size; @@ -525,10 +532,17 @@ link_elf_link_preload(linker_class_t cls, const char *filename, vnet_data_copy(vnet_data, shdr[i].sh_size); ef->progtab[pb].addr = vnet_data; #endif - } else if (ef->progtab[pb].name != NULL && - !strcmp(ef->progtab[pb].name, ".ctors")) { - lf->ctors_addr = ef->progtab[pb].addr; - lf->ctors_size = shdr[i].sh_size; + } else if ((ef->progtab[pb].name != NULL && + strcmp(ef->progtab[pb].name, ".ctors") == 0) || + shdr[i].sh_type == SHT_INIT_ARRAY) { + if (lf->ctors_addr != 0) { + printf( + "%s: multiple ctor sections in %s\n", + __func__, filename); + } else { + lf->ctors_addr = ef->progtab[pb].addr; + lf->ctors_size = shdr[i].sh_size; + } } /* Update all symbol values with the offset. */ @@ -773,6 +787,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, #ifdef __amd64__ case SHT_X86_64_UNWIND: #endif + case SHT_INIT_ARRAY: + case SHT_FINI_ARRAY: if ((shdr[i].sh_flags & SHF_ALLOC) == 0) break; ef->nprogtab++; @@ -894,6 +910,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, #ifdef __amd64__ case SHT_X86_64_UNWIND: #endif + case SHT_INIT_ARRAY: + case SHT_FINI_ARRAY: if ((shdr[i].sh_flags & SHF_ALLOC) == 0) break; alignmask = shdr[i].sh_addralign - 1; @@ -971,6 +989,8 @@ link_elf_load_file(linker_class_t cls, const char *filename, #ifdef __amd64__ case SHT_X86_64_UNWIND: #endif + case SHT_INIT_ARRAY: + case SHT_FINI_ARRAY: if ((shdr[i].sh_flags & SHF_ALLOC) == 0) break; alignmask = shdr[i].sh_addralign - 1; @@ -979,9 +999,18 @@ link_elf_load_file(linker_class_t cls, const char *filename, if (ef->shstrtab != NULL && shdr[i].sh_name != 0) { ef->progtab[pb].name = ef->shstrtab + shdr[i].sh_name; - if (!strcmp(ef->progtab[pb].name, ".ctors")) { - lf->ctors_addr = (caddr_t)mapbase; - lf->ctors_size = shdr[i].sh_size; + if (!strcmp(ef->progtab[pb].name, ".ctors") || + shdr[i].sh_type == SHT_INIT_ARRAY) { + if (lf->ctors_addr != 0) { + printf( + "%s: multiple ctor sections in %s\n", + __func__, filename); + } else { + lf->ctors_addr = + (caddr_t)mapbase; + lf->ctors_size = + shdr[i].sh_size; + } } } else if (shdr[i].sh_type == SHT_PROGBITS) ef->progtab[pb].name = "<>";