On Mon, 23 Oct 2023 at 16:30, Jan Hubicka <hubi...@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 >