public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: edk2-devel-groups-io <devel@edk2.groups.io>,
	rebecca@bsdio.com, Liming Gao <gaoliming@byosoft.com.cn>,
	Bob Feng <bob.c.feng@intel.com>,
	"Chen, Christine" <yuwei.chen@intel.com>
Cc: "Rudolph, Patrick" <patrick.rudolph@9elements.com>,
	Lean Sheng Tan <sheng.tan@9elements.com>,
	Pedro Falcato <pedro.falcato@gmail.com>,
	Vitaly Cheptsov <vit9696@protonmail.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Steven Shi <steven.shi@intel.com>
Subject: Role of DLINK2_FLAGS and link-time option consistency
Date: Fri,  7 Apr 2023 10:13:56 +0000	[thread overview]
Message-ID: <6DC21A1C-4321-499F-ACCD-D5C81D20DB11@posteo.de> (raw)

Good day everyone,

I've been asked to check the following patch: https://edk2.groups.io/g/devel/message/102168

One thing I noticed was that -no-pie is added to DLINK2_FLAGS, not DLINK_FLAGS. For MSVC toolchains, DLINK2_FLAGS is used for a separate linker step [1] introduced by [2], which makes sense to me. For GCC* and CLANG* toolchains, however, I haven't really been able to understand its purpose. Generally, DLINK_FLAGS and DLINK2_FLAGS are used as part of the same command in the same fashion, e.g., [3]. The main difference I've been able to spot is that the linker step for 16-bit ASM files omits DLINK2_FLAGS, but passes DLINK_FLAGS [4]. As MSVC uses a completely different linker flags macro for these files and XCODE* toolchains use the static linker, it appears to be the semantics of DLINK2_FLAGS are different between toolchains. That's my confusion for the consumer side, I don't understand the exact purpose, or why 16-bit ASM in particular is special here. DLINK2_FLAGS unfortunately seems to date back to the "Sync BaseTools" SVN commits, so I didn't find much with blame.

For the producer side, I noticed --pie is passed for DLINK_FLAGS [5]. On the other hand, the IA32 GCC definitions override this with -no-pie, but in DLINK2_FLAGS (which the patch in question replicates). It's my understand that this means the linker step for 16-bit ASM files will be the only linker step in a IA32 build process to use --pie, while all other steps will have the -no-pie override. For the current codebase, there probably isn't much of a difference. However, for a well-defined build behaviour, don't we need to pass mostly the same linker flags (at the very least PIE-related flags) to all steps in the process? Is there a particular reason for how things work the way they do right now?

I've also tried to look at which kinds of flags are generally passed as DLINK_FLAGS vs DLINK2_FLAGS. For some reason, the linker script and related symbol definitions generally seem to be passed via DLINK2_FLAGS [8] as per [9]. I could imagine a possible rationale could be selective replacement, where a platform can discard-and-reassign DLINK2 to pass its own linker script? I didn't find any evidence for this though. With Pedro, I discussed various other possibilities for what could be the rationale for DLINK2_FLAGS, but pretty much failed. One was, that one of them is meant to be passed to the linker directly, while the other was supposed to be passed to the compiler (CC may be DLINK, or they may be different). However, there is a very inconsistent usage of "-Wl" between the two and LD does not support -Wl.

Another (rather unrelated) oddity we noticed is that CLANGDWARF passes different optimization levels to CC and DLINK2 [8], which I'm neither sure whether it is safe to do so, nor whether CC's -Oz really does much now, considering LTO will be on.

Any help with understanding the current design is appreciated, thanks!

Best regards,
Marvin


[1]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/build_rule.template#L289-L291

[2]
https://github.com/tianocore/edk2/commit/578211b882fa99b1f7c82c3e5fd7eeee1510772c

[3]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/build_rule.template#L297

[4]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/build_rule.template#L503

[5]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/tools_def.template#L1858

[6]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/tools_def.template#L2303

[7]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/tools_def.template#L1859

[8]
https://github.com/tianocore/edk2/blob/cdf6ff1719a9453351baec4bd32fcfc30e9ceeac/BaseTools/Conf/tools_def.template#L2937-L2939

[9]
https://github.com/tianocore/edk2/commit/6d732bbbc2b0463f367ceca381cb1861d52cf735


             reply	other threads:[~2023-04-07 10:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 10:13 Marvin Häuser [this message]
2023-04-07 11:02 ` [edk2-devel] Role of DLINK2_FLAGS and link-time option consistency Ard Biesheuvel
2023-04-07 11:05   ` Marvin Häuser
2023-04-07 12:00     ` Ard Biesheuvel
2023-04-15 19:33       ` Marvin Häuser

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=6DC21A1C-4321-499F-ACCD-D5C81D20DB11@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