From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id CDCDB3858D37 for ; Mon, 23 Oct 2023 13:06:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDCDB3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CDCDB3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::230 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698066370; cv=none; b=irwc1mbT6MUaSGcIu4bGYWuODCTtzKteBrqzBOhkuRFZDbLIWc40l6gbtEqVIDVdkWnFpygtkm6j/+iXGskay5sfePXyTRbgzRZ2ZW5TO14NNUfpEPTdsuipZvCkrSlcYdpB5mEuOmenS9G+iS98dDj7taZYnxpofB/DeDnlGj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698066370; c=relaxed/simple; bh=N/5+qYfFmbwJ9PCg/UtWnZkBNPTeOpp7UugLoe67UfM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=NIcv0qfHf6x4lCpOSFb/1ETIAszn8CyEjvjmYKyvCxhYya5cHy0m5VVC45sOqkkEjWD4zTKwVaDSvudmwCFRbDtoyP6vro8IV+pyrQEXmSvC3jSosrhqMgvFiy6Fm+chlghQzNAapE93CreDOvlfmlTPhXVPaiGwwZI7fE35L7I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3b2b1af964dso2388615b6e.1 for ; Mon, 23 Oct 2023 06:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698066368; x=1698671168; darn=gcc.gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=QwGqyzzkEPi5TGN+8bOSRp9Bpbq+FhYAwLci62/GRPU=; b=HMVzLVRote4inAfYr0RS8dIsqgKfdKE7jRIa5Koh2AdjA4c+xcuJDDH192zWeCrx09 wuEhDlUENVQPSdZJjt5hBaUfQQQ6l50quX6gcOO7YD87eMwuTK7Z5qNj80KmqdLl5pir 5kCVc3Meg3CAoQXI1jDTI2Lm05dOItWkCOowsOBXMaF3CSylY6eg/3WzhOMmEZZScfmG IX+otho7/0ULzvhJxiX2rjAVVVdu5vn0Wma9Qq3m9Duu1LwcNCvLTYOJ2rEd0gvANROm niI74cnALEuqL0xT3yI4m/1SOW3pHqKuyS0jeywNv1/9MtDlonR3eN8T33kTqzh/qwGG wsXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698066368; x=1698671168; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QwGqyzzkEPi5TGN+8bOSRp9Bpbq+FhYAwLci62/GRPU=; b=Pub1SoMPMFLW172SK2Yi1u912ESpofhvp5J8MWew7c4CP8lAom8IcgecbdWxH2vRcI tvHcfnThzuJ+dupailbJ8VdFewYb2qwHHw8ZqCrCbr0UNm54SDcbOLC4PYYk2newVIED DijVwrlXyaaWvZsoB2ksS8cKfOUhLLobJHbblsMHB8rxcXd5QxO81fcPj5en2tft6bfS xCSVMC5igoJdCWfzNOFXD6movyVi1bW6UqbaLKlUnDkcDQbw1F8RUplQlSLGwn7VH5YX 8DA1ZGuEekJq2+ZOoXHz58Nyk6rrG2bZkmt1AD6FhDcTarobdABIn4H01pAnXHDE7Uw8 ewyA== X-Gm-Message-State: AOJu0YzvcOzfDN1CDX92sCHCjOzOrYdBIuO20umZYWl1645EOFWMkGhs Y7dTZPKR6BqixhiPqMC0s6pB+Xsrgf0Fxy+/xNw= X-Google-Smtp-Source: AGHT+IGFs14S/Uf9Fe5mT7NQ3x/xky/AbDmNWhmARaG4asxkGpk9f27ROzmibJqQ2L80/9y7eG3G1NzTO9vWgRURMDM= X-Received: by 2002:a05:6808:1b06:b0:3a8:6b4d:6b78 with SMTP id bx6-20020a0568081b0600b003a86b4d6b78mr10399981oib.35.1698066367776; Mon, 23 Oct 2023 06:06:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rishi Raj Date: Mon, 23 Oct 2023 18:35:56 +0530 Message-ID: Subject: Re: [PATCH][WIP] libiberty: Support for relocation output To: Jan Hubicka , gcc-patches@gcc.gnu.org, Martin Jambor Content-Type: multipart/alternative; boundary="000000000000a80ce3060861e2cb" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000a80ce3060861e2cb Content-Type: text/plain; charset="UTF-8" On Mon, 23 Oct 2023 at 16:30, Jan Hubicka 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 > --000000000000a80ce3060861e2cb--