This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Implement x86 SIZE32/SIZE64 relocations
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha at sourceware dot org, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Wed, 16 Jan 2013 10:19:45 +0100
- Subject: Re: [PATCH] Implement x86 SIZE32/SIZE64 relocations
- References: <20130115214514.GA12687@intel.com>
On Tuesday, January 15, 2013 13:45:14 H.J. Lu wrote:
> Hi
>
> Back to 2005, Solaris added R_386_SIZE32, R_X86_64_SIZE32 and
> R_X86_64_SIZE64, which are resolved to symbol size plus addend. But
> they aren't implemented in glibc. This patch implements them. They
> can used to improve address sanitizer for global common symbols:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55739
>
> OK to install?
>
> BTW, I will also implement them in binutils.
>
>
> H.J.
> ---
> elf/elf.h | 2 +-
> sysdeps/i386/dl-machine.h | 9 +++++++++
> sysdeps/x86_64/dl-machine.h | 25 +++++++++++++++++++++++++
> 4 files changed, 44 insertions(+), 1 deletion(-)
>
> 2013-01-15 H.J. Lu <hongjiu.lu@intel.com>
>
> * elf/elf.h (R_386_SIZE32): New relocation.
> * sysdeps/i386/dl-machine.h (elf_machine_rel): Handle
> R_386_SIZE32.
> (elf_machine_rela): Likewise.
> * sysdeps/x86_64/dl-machine.h (R_X86_64_SIZE): New macro.
> (elf_machine_rela): Handle R_X86_64_SIZE64, R_X86_64_SIZE
> and R_X86_64_SIZE32.
>
> diff --git a/elf/elf.h b/elf/elf.h
> index 9a31373..9bc5004 100644
> --- a/elf/elf.h
> +++ b/elf/elf.h
> @@ -1229,7 +1229,7 @@ typedef struct
> #define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol
*/
> #define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */
> #define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block
> */ -/* 38? */
> +#define R_386_SIZE32 38 /* 32-bit symbol size */
> #define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor.
*/
> #define R_386_TLS_DESC_CALL 40 /* Marker of call through TLS
> descriptor for
> diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
> index 9e36687..a1e40d8 100644
> --- a/sysdeps/i386/dl-machine.h
> +++ b/sysdeps/i386/dl-machine.h
> @@ -348,6 +348,12 @@ elf_machine_rel (struct link_map *map, const
> Elf32_Rel *reloc,
>
> switch (r_type)
> {
> +# ifndef RTLD_BOOTSTRAP
> + case R_386_SIZE32:
> + /* Set to symbol size plus addend. */
> + *reloc_addr += sym->st_size;
> + break;
> +# endif
> case R_386_GLOB_DAT:
> case R_386_JMP_SLOT:
> *reloc_addr = value;
> @@ -507,6 +513,9 @@ elf_machine_rela (struct link_map *map, const
> Elf32_Rela *reloc,
>
> switch (ELF32_R_TYPE (reloc->r_info))
> {
> + case R_386_SIZE32:
> + /* Set to symbol size plus addend. */
> + value = sym->st_size;
> case R_386_GLOB_DAT:
> case R_386_JMP_SLOT:
> case R_386_32:
> diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
> index 660f1aa..382caa4 100644
> --- a/sysdeps/x86_64/dl-machine.h
> +++ b/sysdeps/x86_64/dl-machine.h
> @@ -190,6 +190,13 @@ _dl_start_user:\n\
> /* The x86-64 never uses Elf64_Rel/Elf32_Rel relocations. */
> #define ELF_MACHINE_NO_REL 1
>
> +/* Size relocation. */
> +#ifdef __ILP32__
> +# define R_X86_64_SIZE R_X86_64_SIZE32
> +#else
> +# define R_X86_64_SIZE R_X86_64_SIZE64
> +#endif
> +
Since this is only used once, I would not define this but do a proper
ifdef where this is needed.
> /* We define an initialization function. This is called very early
> in _dl_sysdep_start. */
> #define DL_PLATFORM_INIT dl_platform_init ()
> @@ -286,6 +293,19 @@ elf_machine_rela (struct link_map *map, const
> ElfW(Rela) *reloc,
>
> switch (r_type)
> {
> +# ifndef RTLD_BOOTSTRAP
> +# ifdef __ILP32__
> + case R_X86_64_SIZE64:
> + /* Set to symbol size plus addend. */
> + *((Elf64_Addr *) (uintptr_t) reloc_addr)
> + = (Elf64_Addr) sym->st_size + reloc->r_addend;
> + break;
> +# endif
> +
> + case R_X86_64_SIZE:
> + /* Set to symbol size plus addend. */
> + value = sym->st_size;
> +# endif
> case R_X86_64_GLOB_DAT:
> case R_X86_64_JUMP_SLOT:
> *reloc_addr = value + reloc->r_addend;
> @@ -394,6 +414,11 @@ elf_machine_rela (struct link_map *map, const
> ElfW(Rela) *reloc, relocation updates the whole 64-bit entry. */
> *(Elf64_Addr *) reloc_addr = (Elf64_Addr) value + reloc->r_addend;
> break;
> +# ifndef __ILP32__
> + case R_X86_64_SIZE32:
> + /* Set to symbol size plus addend. */
> + value = sym->st_size;
> +# endif
> case R_X86_64_32:
> value += reloc->r_addend;
> *(unsigned int *) reloc_addr = value;
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126