[PATCH v6 2/9] elf: Parse gnu properties for statically linked binaries
Yury Khrustalev
yury.khrustalev@arm.com
Tue Mar 18 10:25:28 GMT 2025
On Tue, Mar 11, 2025 at 02:09:49PM -0300, Adhemerval Zanella wrote:
> It allows static binary to opt-in of memory sealing. The aarch64
> already does it for GCS, so refactor it to use
> __libc_process_gnu_attributes instead.
>
> Checked on x86_64-linux-gnu.
> ---
> csu/libc-start.c | 4 ++
> elf/dl-support.c | 13 ++++++
> sysdeps/generic/libc-prop.h | 44 ++++++++++++++++++++
> sysdeps/unix/sysv/linux/aarch64/libc-start.h | 11 -----
> sysdeps/x86/dl-prop.h | 4 +-
> 5 files changed, 64 insertions(+), 12 deletions(-)
> create mode 100644 sysdeps/generic/libc-prop.h
>
> + /* Process program headers again, but scan them backwards so
> + that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. */
Why do we need to process headers again?
> + for (const ElfW(Phdr) *ph = &_dl_phdr[_dl_phnum]; ph != _dl_phdr; --ph)
> + switch (ph[-1].p_type)
> + {
> + case PT_NOTE:
> + _dl_process_pt_note (&_dl_main_map, -1, &ph[-1]);
> + break;
> + case PT_GNU_PROPERTY:
> + _dl_process_pt_gnu_property (&_dl_main_map, -1, &ph[-1]);
> + break;
> + }
>
> if ((__glibc_unlikely (GL(dl_stack_flags)) & PF_X)
> && TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL) == 0)
> diff --git a/sysdeps/generic/libc-prop.h b/sysdeps/generic/libc-prop.h
> new file mode 100644
> index 0000000000..723575d29b
> --- /dev/null
> +++ b/sysdeps/generic/libc-prop.h
> @@ -0,0 +1,44 @@
> +/* Support for GNU properties for static builds. Generic version.
> + Copyright (C) 2025 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef _LIBC_PROP_H
> +#define _LIBC_PROP_H
> +
> +#include <dl-prop.h>
> +
> +/* Called at the start of program execution to handle GNU attribute from
> + PT_NOTE / PT_GNU_PROPERTY. Must be on a top-level stack frame that does
> + not return. */
> +static __always_inline void
> +__libc_process_gnu_attributes (void)
I think that "__libc_process_gnu_properties" may be a better name. There may
be a need in the future to process build attributes [1] and the name of the
function above might be confusing.
[1] https://github.com/smithp35/abi-aa/blob/build-attributes/buildattr64/buildattr64.rst
Kind regardsm
Yury
More information about the Libc-alpha
mailing list