From: "Marvin Häuser" <mhaeuser@posteo.de>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
devel@edk2.groups.io, Yuwei Chen <yuwei.chen@intel.com>,
Oliver Steffen <osteffen@redhat.com>,
Bob Feng <bob.c.feng@intel.com>,
Daniel Schaefer <git@danielschaefer.me>,
Chao Li <lichao@loongson.cn>,
Dongyan Qian <qiandongyan@loongson.cn>,
Michael D Kinney <michael.d.kinney@intel.com>,
Pawel Polawski <ppolawsk@redhat.com>,
Baoqi Zhang <zhangbaoqi@loongson.cn>,
Leif Lindholm <quic_llindhol@quicinc.com>,
Rebecca Cran <rebecca@bsdio.com>,
Zhiguang Liu <zhiguang.liu@intel.com>,
Sunil V L <sunilvl@ventanamicro.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Liming Gao <gaoliming@byosoft.com.cn>
Subject: Re: [PATCH v5 02/10] MdePkg: don't set visibility to hidden
Date: Fri, 21 Apr 2023 07:46:01 +0000 [thread overview]
Message-ID: <B8F89389-EFD1-4960-AA32-462E7CC06784@posteo.de> (raw)
In-Reply-To: <CAMj1kXFKJbnVpUotFh2aihc+8Z_GM-WT90ZBm_UwzDgvWqcpnQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2717 bytes --]
> On 21. Apr 2023, at 09:21, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Fri, 21 Apr 2023 at 08:49, Gerd Hoffmann <kraxel@redhat.com> wrote:
>>
>>> On Fri, Apr 21, 2023 at 06:01:11AM +0000, Marvin Häuser wrote:
>>>
>>>> On 21. Apr 2023, at 06:45, Gerd Hoffmann <kraxel@redhat.com> wrote:
>>>>
>>>> Not needed any more on modern toolchains, they are better
>>>> in not creating a GOT without this trick.
>>>
>>> Hi Gerd,
>>>
>>> Thanks! Just out of interest, how did you test this and what were the results?
>>
>> Patch #1, adding a linker script assert as suggested by ard, then:
>>
>> * compile + test on my local workstation (fedora 37, gcc 12).
>> * run CI
>> * compile on some older distros:
>> - rhel-8 (gcc 8)
>> - ubuntu-18.04 (gcc 7)
>>
>
> I just realized that on x86, GenFw has some code to deal with GOT
> entries if they are emitted. I'm not sure how often that gets
> exercised, given our prior use of hidden visibility, but at least the
> GOT entries should be covered by relocations if they exist.
>
> *However*, one thing we are not taking into account is the fact that
> relaxations are not usually reflected in the relocations emitted by
> the compiler when using --emit-relocs. So we might end up with
> occurrences like the below (taken from the Linux kernel but the idea
> is the same)
>
> ffffffff82fa59d5: 4c 8d 0d 24 66 88 ff lea -0x7799dc(%rip),%r9
> ffffffff82fa59d8: R_X86_64_REX_GOTPCRELX level4_kernel_pgt-0x4
> ffffffff82fa59dc: 49 8d 69 67 lea 0x67(%r9),%rbp
> ffffffff82fa59e0: 4c 8d 15 19 76 88 ff lea -0x7789e7(%rip),%r10
> ffffffff82fa59e3: R_X86_64_REX_GOTPCRELX level3_kernel_pgt-0x4
>
> So here, the GOT loads have been relaxed into LEA instructions, but
> GenFw will decode the immediate and assume it points to the GOT entry
> rather than the variable itself, and happily emit a PE relocation for
> it.
>
> So it would be better to ASSERT() on non-empty GOT, and ignore such
> GOTPCREL relocations instead of attempting to relocate the GOT entries
> they (used to) refer to.
Hmm, we’ve been toying with using only PIE relocs for X64 for a bit and finally merged it into master, so far no issues:
https://github.com/acidanthera/audk/commit/92bb32130bcd0c35e48bdc308a18e5bc74cbaa42
https://github.com/acidanthera/audk/commit/42988773a06f9d6bf345fcbe82c1082ff1cfa2af
In fact (I *did not* confirm this, it’s only a report I got), it seems to fix something regarding the stack protector. I’d not be surprised if there are edge-cases where -q does not get all necessary relocs when PIE is enabled.
Best regards,
Marvin
[-- Attachment #2: Type: text/html, Size: 5704 bytes --]
next prev parent reply other threads:[~2023-04-21 7:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-21 4:45 [PATCH v5 00/10] BaseTools: remove duplicate includes Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 01/10] BaseTools: make sure the got is empty Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 02/10] MdePkg: don't set visibility to hidden Gerd Hoffmann
2023-04-21 6:01 ` Marvin Häuser
2023-04-21 6:49 ` Gerd Hoffmann
2023-04-21 6:57 ` Marvin Häuser
2023-04-21 9:23 ` Gerd Hoffmann
2023-04-21 7:21 ` Ard Biesheuvel
2023-04-21 7:46 ` Marvin Häuser [this message]
2023-05-05 14:33 ` Rebecca Cran
2023-05-09 6:08 ` Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 03/10] BaseTools: remove WinNtInclude.h Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 04/10] BaseTools: remove duplicate includes: <arch>/ProcessorBind.h Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 05/10] BaseTools: remove duplicate includes: IndustryStandard/Acpi*.h Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 06/10] MdePkg/PeImage.h: add bits from BaseTools version Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 07/10] BaseTools: drop IMAGE_FILE_MACHINE_ARM hacks Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 08/10] BaseTools: switch from EFI_IMAGE_MACHINE_* to IMAGE_FILE_MACHINE_* Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 09/10] BaseTools: remove duplicate includes: IndustryStandard/PeImage.h Gerd Hoffmann
2023-04-21 4:45 ` [PATCH v5 10/10] BaseTools: remove duplicate includes: IndustryStandard/*.h Gerd Hoffmann
2023-05-04 10:11 ` [PATCH v5 00/10] BaseTools: remove duplicate includes Gerd Hoffmann
2023-05-04 12:38 ` 回复: " gaoliming
2023-05-04 12:40 ` Rebecca Cran
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=B8F89389-EFD1-4960-AA32-462E7CC06784@posteo.de \
--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