public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Rishi Raj <rishiraj45035@gmail.com>
To: Jan Hubicka <hubicka@ucw.cz>,
	gcc-patches@gcc.gnu.org,  Martin Jambor <mjambor@suse.cz>
Subject: Re: [PATCH][WIP] libiberty: Support for relocation output
Date: Mon, 23 Oct 2023 18:35:56 +0530	[thread overview]
Message-ID: <CA+1a67OGLC_ktCH4UZcK_n=RwLgrUTQBLdDyc6AJA2Tk5cotXA@mail.gmail.com> (raw)
In-Reply-To: <ZTZSXMzz0PtJZKNo@kam.mff.cuni.cz>

[-- Attachment #1: Type: text/plain, Size: 3570 bytes --]

On Mon, 23 Oct 2023 at 16:30, Jan Hubicka <hubicka@ucw.cz> wrote:

> > This patch teaches libiberty to output X86-64 Relocations.
> Hello,
> for actual patch submission you will need to add changelog :)
>
I know, right :).

> > diff --git a/libiberty/simple-object-elf.c
> b/libiberty/simple-object-elf.c
> > index 86b7a27dc74..0bbaf4b489f 100644
> > --- a/libiberty/simple-object-elf.c
> > +++ b/libiberty/simple-object-elf.c
> > @@ -238,6 +238,7 @@ typedef struct
> >  #define STT_NOTYPE 0 /* Symbol type is unspecified */
> >  #define STT_OBJECT 1 /* Symbol is a data object */
> >  #define STT_FUNC 2 /* Symbol is a code object */
> > +#define STT_SECTION 3 /* Symbol is associate with a section */
> Associated I guess.
> >  #define STT_TLS 6 /* Thread local data object */
> >  #define STT_GNU_IFUNC 10 /* Symbol is an indirect code object */
> >
> > @@ -248,6 +249,63 @@ typedef struct
> >  #define STV_DEFAULT 0 /* Visibility is specified by binding type */
> >  #define STV_HIDDEN 2 /* Can only be seen inside currect component */
> >
> > +typedef struct
> > +{
> > +  unsigned char r_offset[4]; /* Address */
> > +  unsigned char r_info[4];  /* relocation type and symbol index */
> > +} Elf32_External_Rel;
> > +
> > +typedef struct
> > +{
> > +  unsigned char r_offset[8]; /* Address */
> > +  unsigned char r_info[8]; /* Relocation type and symbol index */
> > +} Elf64_External_Rel;
> > +typedef struct
> > +{
> > +  unsigned char r_offset[4]; /* Address */
> > +  unsigned char r_info[4];  /* Relocation type and symbol index */
> > +  char r_addend[4]; /* Addend */
> > +} Elf32_External_Rela;
> > +typedef struct
> > +{
> > +  unsigned char r_offset[8]; /* Address */
> > +  unsigned char r_info[8]; /* Relocation type and symbol index */
> > +  unsigned char r_addend[8]; /* Addend */
> > +} Elf64_External_Rela;
> > +
> > +/* How to extract and insert information held in the r_info field.  */
> > +
> > +#define ELF32_R_SYM(val) ((val) >> 8)
> > +#define ELF32_R_TYPE(val) ((val) & 0xff)
> > +#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
> > +
> > +#define ELF64_R_SYM(i) ((i) >> 32)
> > +#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
> > +#define ELF64_R_INFO(sym,type) ((((unsigned long) (sym)) << 32) +
> (type))
> > +
> > +/* AMD x86-64 relocations.  */
> > +#define R_X86_64_NONE 0 /* No reloc */
> > +#define R_X86_64_64 1 /* Direct 64 bit  */
> > +#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
> > +#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
> > +#define R_X86_64_PLT32 4 /* 32 bit PLT address */
> > +#define R_X86_64_COPY 5 /* Copy symbol at runtime */
> > +#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
> > +#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
> > +#define R_X86_64_RELATIVE 8 /* Adjust by program base */
> > +#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative
> > +   offset to GOT */
> > +#define R_X86_64_32 10 /* Direct 32 bit zero extended */
> > +#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
> > +#define R_X86_64_16 12 /* Direct 16 bit zero extended */
>
> This will eventually need to go into per-architecture table.
> You support only those needed for Dwarf2out ouptut, right?
>
Yeah, as of now.

>
> I think we need Iant's opinion on thi part of patch (he is the
> maintainer of simple-object) but to me it looks reasonable. For longer
> term it will be necessary to think how to make this extensible to other
> architectures without writting too much of code.  (have some more
> declarative way to specify relocations we output)
>
Make sense.

>
> Honza
>

      reply	other threads:[~2023-10-23 13:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-23  3:32 Rishi Raj
2023-10-23 11:00 ` Jan Hubicka
2023-10-23 13:05   ` Rishi Raj [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+1a67OGLC_ktCH4UZcK_n=RwLgrUTQBLdDyc6AJA2Tk5cotXA@mail.gmail.com' \
    --to=rishiraj45035@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=mjambor@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).