[PATCH v4] elf: Add DL_ADDRESS_WITHOUT_RELOC [BZ #33088]

H.J. Lu hjl.tools@gmail.com
Mon Jun 30 08:23:11 GMT 2025


On Mon, Jun 23, 2025 at 9:40 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > diff --git a/elf/dl-before-reloc.h b/elf/dl-before-reloc.h
> > new file mode 100644
> > index 0000000000..042ee0bac7
> > --- /dev/null
> > +++ b/elf/dl-before-reloc.h
> > @@ -0,0 +1,27 @@
> > +/* Facilities before run-time relocation.
> > +   Copyright (C) 2025 Free Software Foundation, Inc.
> > +   Copyright The GNU Toolchain Authors.
> > +   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/>.  */
> > +
> > +/* Evaluate EXPR without run-time relocation for it.  EXPR should be an
> > +   array, an address of an object, or a string literal.  */
> > +#define DL_ADDRESS_WITHOUT_RELOC(expr)               \
> > +  ({                                         \
> > +     __auto_type _result = (expr);           \
> > +     asm ("" : "+r" (_result));                      \
> > +     _result;                                        \
> > +   })
>
> My previous comment got lost somewhere:
>
> The asm construct should only be used for
> !HIDDEN_VAR_NEEDS_DYNAMIC_RELOC architectures.  Dynamic relocations are
> ever-present for HIDDEN_VAR_NEEDS_DYNAMIC_RELOC architectures, so this
> kludge is not needed.

Fixed.

> I think <dl-before-reloc.h> should be named something else
> (<dl-avoid-reloc.h>?) and perhaps go into into the include/ directory.
> Although I don't see any uses of elf/ yet.

I put it include/elf.h:

https://patchwork.sourceware.org/project/glibc/list/?series=49098

> My hope is that we can stick this into all the appropriate places and
> then have a variant of the check-localplt test (likely rewritten in
> Python) that detects regressions for !HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
> architectures.  (Obviously, this shouldn't be part of the patch.)

-- 
H.J.


More information about the Libc-alpha mailing list