From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by sourceware.org (Postfix) with ESMTPS id 7EEB93858C53 for ; Wed, 20 Apr 2022 13:32:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EEB93858C53 Received: by mail-oo1-xc29.google.com with SMTP id f13-20020a4aa68d000000b0033a2c53d0baso295696oom.0 for ; Wed, 20 Apr 2022 06:32:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=99MYc3z3bwYaZQo5MNhHtpd6BpKe/+3Y6S/AqLNVIIE=; b=ySPZLr4MSv5Ug2PlZ4AYyVvn9qg6+ePfakU5MY/F9qowy1VO6/aGWBkRKUFqsiDyES 1ih5msQb9E/WqgYC58H3YPorwXzBiUJlBaVFIvsCoTIpCUMcG9l9CtqTZsOrKBuNn+HW QDuktU78+POrQWWSRQ349Pdjl28gFBSlybDd69ZQHSdPzauQ3olzZCfXFyP6nwAuw4NM Y8AscJ/dzfJmnYQj0Q5WJdEYGZe3ls0uWbeyI2jjQRrXsUMjAkjRKHshgp7AUauSUsq6 RN8e+N6B3pC08tAJkPIYNShnKn/TmVYiQfek8eueh/UrwgyxItVdAhyLkucDn9NVmHCp ELVw== X-Gm-Message-State: AOAM5302SIlhHfuykdULgjQZRda5qesH3YK96ysDjAwb5SCXMpRUvTpr QYK9gdj4pUyyaC1Tf0VuREf5IQ== X-Google-Smtp-Source: ABdhPJx7ZCIpGXJDTwfkJd/E+rt8MDf14fboQiOw7Y3pQ/Kiq2H5vN86I/oCmUrQkF2ElFp5Zc1vuQ== X-Received: by 2002:a4a:8783:0:b0:324:b9a2:d605 with SMTP id b3-20020a4a8783000000b00324b9a2d605mr7091440ooi.38.1650461568774; Wed, 20 Apr 2022 06:32:48 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:c9d0:24b1:bd98:2ef4:714c? ([2804:431:c7ca:c9d0:24b1:bd98:2ef4:714c]) by smtp.gmail.com with ESMTPSA id w2-20020a4a7642000000b0033a2cdbe62fsm4778071ooe.45.2022.04.20.06.32.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Apr 2022 06:32:48 -0700 (PDT) Message-ID: <434a85d7-0842-4387-4773-1bb3a9fb86d4@linaro.org> Date: Wed, 20 Apr 2022 10:32:45 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v10 2/7] Add GLIBC_ABI_DT_RELR for DT_RELR support Content-Language: en-US To: "H.J. Lu" , libc-alpha@sourceware.org References: <20220414232129.1886210-1-hjl.tools@gmail.com> <20220414232129.1886210-3-hjl.tools@gmail.com> From: Adhemerval Zanella In-Reply-To: <20220414232129.1886210-3-hjl.tools@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2022 13:32:51 -0000 On 14/04/2022 20:21, H.J. Lu wrote: > The EI_ABIVERSION field of the ELF header in executables and shared > libraries can be bumped to indicate the minimum ABI requirement on the > dynamic linker. However, EI_ABIVERSION in executables isn't checked by > the Linux kernel ELF loader nor the existing dynamic linker. Executables > will crash mysteriously if the dynamic linker doesn't support the ABI > features required by the EI_ABIVERSION field. The dynamic linker should > be changed to check EI_ABIVERSION in executables. > > Add a glibc version, GLIBC_ABI_DT_RELR, to indicate DT_RELR support so > that the existing dynamic linkers will issue an error on executables with > GLIBC_ABI_DT_RELR dependency. When there is a DT_VERNEED entry with > libc.so on DT_NEEDED, issue an error if there is a DT_RELR entry without > GLIBC_ABI_DT_RELR dependency. > > Support __placeholder_only_for_empty_version_map as the placeholder symbol > used only for empty version map to generate GLIBC_ABI_DT_RELR without any > symbols. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > elf/Makefile | 14 ++++++++++++-- > elf/Versions | 5 +++++ > elf/dl-version.c | 35 +++++++++++++++++++++++++++++++++-- > include/link.h | 2 ++ > scripts/abilist.awk | 2 ++ > scripts/versions.awk | 7 ++++++- > 6 files changed, 60 insertions(+), 5 deletions(-) > > diff --git a/elf/Makefile b/elf/Makefile > index d30d0ee917..ee8778c3a2 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -1110,8 +1110,12 @@ $(eval $(call include_dsosort_tests,dso-sort-tests-1.def)) > $(eval $(call include_dsosort_tests,dso-sort-tests-2.def)) > endif > > -check-abi: $(objpfx)check-abi-ld.out > -tests-special += $(objpfx)check-abi-ld.out > +check-abi: $(objpfx)check-abi-ld.out \ > + $(objpfx)check-abi-version-libc.out > +tests-special += \ > + $(objpfx)check-abi-ld.out \ > + $(objpfx)check-abi-version-libc.out \ > +# tests-special > update-abi: update-abi-ld > update-all-abi: update-all-abi-ld > > @@ -2733,3 +2737,9 @@ $(objpfx)tst-p_align3: $(objpfx)tst-p_alignmod3.so > $(objpfx)tst-p_align3.out: tst-p_align3.sh $(objpfx)tst-p_align3 > $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ > $(evaluate-test) > + > +$(objpfx)check-abi-version-libc.out: $(common-objpfx)libc.so > + LC_ALL=C $(READELF) -V -W $< \ > + | sed -ne '/.gnu.version_d/, /.gnu.version_r/ p' \ > + | grep GLIBC_ABI_DT_RELR > $@; \ > + $(evaluate-test) Ok. > diff --git a/elf/Versions b/elf/Versions > index 8bed855d8c..a9ff278de7 100644 > --- a/elf/Versions > +++ b/elf/Versions > @@ -23,6 +23,11 @@ libc { > GLIBC_2.35 { > _dl_find_object; > } > + GLIBC_ABI_DT_RELR { > + # This symbol is used only for empty version map and will be removed > + # by scripts/versions.awk. > + __placeholder_only_for_empty_version_map; > + } > GLIBC_PRIVATE { > # functions used in other libraries > __libc_early_init; Ok. > diff --git a/elf/dl-version.c b/elf/dl-version.c > index b47bd91727..cda0889209 100644 > --- a/elf/dl-version.c > +++ b/elf/dl-version.c > @@ -214,12 +214,19 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode) > while (1) > { > /* Match the symbol. */ > + const char *string = strtab + aux->vna_name; > result |= match_symbol (DSO_FILENAME (map->l_name), > map->l_ns, aux->vna_hash, > - strtab + aux->vna_name, > - needed->l_real, verbose, > + string, needed->l_real, verbose, > aux->vna_flags & VER_FLG_WEAK); > > + /* 0xfd0e42: _dl_elf_hash ("GLIBC_ABI_DT_RELR"). */ > + if (aux->vna_hash == 0xfd0e42 > + && __glibc_likely (strcmp (string, > + "GLIBC_ABI_DT_RELR") > + == 0)) > + map->l_dt_relr_ref = 1; > + > /* Compare the version index. */ > if ((unsigned int) (aux->vna_other & 0x7fff) > ndx_high) > ndx_high = aux->vna_other & 0x7fff; Ok. > @@ -352,6 +359,30 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode) > } > } > > + /* When there is a DT_VERNEED entry with libc.so on DT_NEEDED, issue > + an error if there is a DT_RELR entry without GLIBC_ABI_DT_RELR > + dependency. */ > + if (dyn != NULL > + && map->l_info[DT_NEEDED] != NULL > + && map->l_info[DT_RELR] != NULL > + && __glibc_unlikely (!map->l_dt_relr_ref)) > + { > + const char *strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]); > + const ElfW(Dyn) *d; > + for (d = map->l_ld; d->d_tag != DT_NULL; ++d) > + if (d->d_tag == DT_NEEDED) > + { > + const char *name = strtab + d->d_un.d_val; > + if (strncmp (name, "libc.so.", 8) == 0) > + { > + _dl_exception_create > + (&exception, DSO_FILENAME (map->l_name), > + N_("DT_RELR without GLIBC_ABI_DT_RELR dependency")); > + goto call_error; > + } > + } > + } > + > return result; > } > Ok. > diff --git a/include/link.h b/include/link.h > index 03db14c7b0..0ac82d7c77 100644 > --- a/include/link.h > +++ b/include/link.h > @@ -177,6 +177,8 @@ struct link_map > lt_library, /* Library needed by main executable. */ > lt_loaded /* Extra run-time loaded shared object. */ > } l_type:2; > + unsigned int l_dt_relr_ref:1; /* Nonzero if GLIBC_ABI_DT_RELR is > + referenced. */ > unsigned int l_relocated:1; /* Nonzero if object's relocations done. */ > unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */ > unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */ Ok. > diff --git a/scripts/abilist.awk b/scripts/abilist.awk > index 24a34ccbed..6cc7af6ac8 100644 > --- a/scripts/abilist.awk > +++ b/scripts/abilist.awk > @@ -55,6 +55,8 @@ $2 == "g" || $2 == "w" && (NF == 7 || NF == 8) { > # caused STV_HIDDEN symbols to appear in .dynsym, though that is useless. > if (NF > 7 && $7 == ".hidden") next; > > + if (version ~ /^GLIBC_ABI_/ && !include_abi_version) next; > + > if (version == "GLIBC_PRIVATE" && !include_private) next; > > desc = ""; > diff --git a/scripts/versions.awk b/scripts/versions.awk > index 357ad1355e..d70b07bd1a 100644 > --- a/scripts/versions.awk > +++ b/scripts/versions.awk > @@ -185,8 +185,13 @@ END { > closeversion(oldver, veryoldver); > veryoldver = oldver; > } > - printf("%s {\n global:\n", $2) > outfile; > oldver = $2; > + # Skip the placeholder symbol used only for empty version map. > + if ($3 == "__placeholder_only_for_empty_version_map;") { > + printf("%s {\n", $2) > outfile; > + continue; > + } > + printf("%s {\n global:\n", $2) > outfile; > } > printf(" ") > outfile; > for (n = 3; n <= NF; ++n) { Ok.