From: "Shi, Steven" <steven.shi@intel.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: edk2-devel-01 <edk2-devel@lists.01.org>,
"Gao, Liming" <liming.gao@intel.com>,
"afish@apple.com" <afish@apple.com>,
"Justen, Jordan L" <jordan.l.justen@intel.com>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [PATCH v2 2/7] BaseTools-GenFw:Add new x86_64 Elf relocation types for PIC/PIE code
Date: Mon, 1 Aug 2016 07:54:15 +0000 [thread overview]
Message-ID: <06C8AB66E78EE34A949939824ABE2B31033824FA@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <CAKv+Gu-HhAK2Ltdz4UucxyXd3G=Z_SptFN-P5DnWBe1mZyYyyQ@mail.gmail.com>
> On 1 August 2016 at 09:19, Shi, Steven <steven.shi@intel.com<mailto:steven.shi@intel.com>> wrote:
> >> >>
> >> >> The fact that it works does not make it safe. Having multiple fixups
> >> >> for the same symbol in the .reloc section is a problem, and so is
> >> >> reapplying GOTPCRELX to places where the original instruction has
> been
> >> >> replaced by the linker.
> >> >>
> >> > [Steven]: I still don't understand why there will be multiple fixups for the
> >> same symbol in the .reloc section?
> >> >
> >>
> >> Remember this example
> >>
> >> >> > int n;
> >> >> > int f () { return n; }
> >> >> > int g () { return n; }
> >> >> > int h () { return n; }
> >>
> >> If every 'return n' results in a GOTPCREL relocation, how are you
> >> going to make sure that the GOT entry for 'n' is only fixed up a
> >> single time?
> >
> > [Steven]: the 'return n' will not result in relocation, but the 'int n' will result
> in the relocation in GOT. The three 'return n' will point to the same 'int n'
> relocation item. So, we need only fixup 'int n' once, all three 'return n' will
> use the correct global 'n' value.
>
> Every 'return n' will result in a GOTPCREL relocation against n. And
> your code emits a relocation for the GOT entry every time.
>
[Steven]: I don't think so. please give a real case and offer its source code to prove " Every 'return n' will result in a GOTPCREL relocation against n ".
> BTW, the 'int n' relocation type in your code on X64 should be
> R_X86_64_GLOB_DAT
> >
>
> R_X86_64_GLOB_DAT is a dynamic relocation type. These are only emitted
> when linking a shared object or a PIE executable, which I would like
> to avoid as well.
>
> The problem with PIE executables is that the .rela.xxx sections
> emitted for each section, and the single .rela section containing the
> dynamic relocations overlap with each other, i.e., places containing
> absolute symbol addresses in the binary will appear in both, and
> emitting reloc fixups for all relocations will result in duplicates.
>
[Steven]: the current GenFw will ignore the single .rela section, because the .rela section info is 0, which target invalid section at all. See below sections example. Current GenFw will only handle the .rela.text and .rela.data relocation sections.
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .note.gnu.build-i NOTE 0000000000000000 00000100
0000000000000024 0000000000000000 A 0 0 4
[ 2] .text PROGBITS 0000000000000240 00000340
00000000000059f8 0000000000000008 AX 0 0 64
[ 3] .rela.text RELA 0000000000000000 00008728
00000000000044d0 0000000000000018 I 10 2 8
[ 4] .data PROGBITS 0000000000005c40 00005d40
0000000000000a68 0000000000000000 WA 0 0 64
[ 5] .rela.data RELA 0000000000000000 0000cbf8
00000000000004b0 0000000000000018 I 10 4 8
[ 6] .rela RELA 00000000000066c0 000067c0
00000000000004b0 0000000000000018 A 0 0 8
> > You can see the 'int myglob' in Eli's example in
> http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-<http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/>
> shared-libraries/<http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/>. The 'int myglob' is same as your 'int n' example.
> >
> > int myglob = 42;
> > int ml_func(int a, int b)
> > {
> > return myglob + a + b;
> > }
> >
>
> Yes, and every reference to 'myglob' will result in a GOTPCREL
> relocation. We must not emit a fixup for myglob every time.
[Steven]: Please give a real case and offer its source code to prove "every reference to 'myglob' will result in a GOTPCREL relocation".
next prev parent reply other threads:[~2016-08-01 7:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1467967364-11556-1-git-send-email-steven.shi@intel.com>
[not found] ` <1467967364-11556-3-git-send-email-steven.shi@intel.com>
2016-07-30 9:25 ` [PATCH v2 2/7] BaseTools-GenFw:Add new x86_64 Elf relocation types for PIC/PIE code Ard Biesheuvel
2016-07-30 14:09 ` Shi, Steven
2016-07-30 14:11 ` Ard Biesheuvel
2016-07-31 3:08 ` Shi, Steven
2016-07-31 5:42 ` Ard Biesheuvel
2016-07-31 19:10 ` Ard Biesheuvel
2016-08-01 4:39 ` Shi, Steven
2016-08-01 5:58 ` Ard Biesheuvel
2016-08-01 6:13 ` Shi, Steven
2016-08-01 6:43 ` Ard Biesheuvel
2016-08-01 7:19 ` Shi, Steven
2016-08-01 7:25 ` Ard Biesheuvel
2016-08-01 7:54 ` Shi, Steven [this message]
2016-08-01 8:00 ` Ard Biesheuvel
2016-08-01 8:28 ` Shi, Steven
[not found] ` <06C8AB66E78EE34A949939824ABE2B31033825EE@shsmsx102.ccr.corp.intel.com>
[not found] ` <CAKv+Gu80u+CJLVtD5tTo5RrJb7LH0Qfnbj=7b7NUqrbf2aOPrA@mail.gmail.com>
[not found] ` <06C8AB66E78EE34A949939824ABE2B31033826FE@shsmsx102.ccr.corp.intel.com>
[not found] ` <CAKv+Gu9MSisR1T_jr=DNyCs24We5=2vUgQZJ9t_rZmCYC8qvHg@mail.gmail.com>
[not found] ` <06C8AB66E78EE34A949939824ABE2B310338275F@shsmsx102.ccr.corp.intel.com>
2016-08-01 10:46 ` Ard Biesheuvel
2016-08-02 11:40 ` Shi, Steven
2016-08-02 12:00 ` Ard Biesheuvel
2016-08-03 20:13 ` Jordan Justen
2016-08-03 20:47 ` Ard Biesheuvel
2016-08-03 20:53 ` Jordan Justen
2016-08-03 20:55 ` Ard Biesheuvel
2016-08-03 23:26 ` Shi, Steven
2016-08-03 20:55 ` Nicolas Owens
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-list 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=06C8AB66E78EE34A949939824ABE2B31033824FA@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/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