From: "Marvin Häuser" <mhaeuser@posteo.de>
To: "Ni, Ray" <ray.ni@intel.com>
Cc: "Rudolph, Patrick" <patrick.rudolph@9elements.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>,
"Dong, Guo" <guo.dong@intel.com>, "Guo, Gua" <gua.guo@intel.com>,
"Lu, James" <james.lu@intel.com>,
"ardb@kernel.org" <ardb@kernel.org>
Subject: Re: [PATCH 2/3] BaseTools/Conf/tools_def: Fix CLANGDWARF_IA32_X64
Date: Fri, 31 Mar 2023 14:58:53 +0000 [thread overview]
Message-ID: <3FB3223E-3591-4B15-AE1F-757A88D86074@posteo.de> (raw)
In-Reply-To: <MN6PR11MB8244A9CB742C5E20EF1C73E48C8F9@MN6PR11MB8244.namprd11.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 4217 bytes --]
> On 31. Mar 2023, at 16:41, Ni, Ray <ray.ni@intel.com> wrote:
>
> Why ELF header overflows into .text section?
That's a good question, isn't it? :)
From what I can see, these binaries don't pass post-processing like GenFw or such. GCC (and I think thus CLANGDWARF?) gets an extra objcopy step as part of linking [2], but the arguments are empty [3] and thus should be no-op (I hope?).
I suppose potential candidates are:
1) A bug in the LLD linker used by CLANGDWARF for IA32 and X64. That would be very surprising to me, especially as no other platform reported issues and LLD is well-established. But who knows, generally ELFs will have large alignment values compared to the 64 Bytes used by edk2.
2) A bug in llvm-objcopy used by UniversalPayloadBuild.py [1]. I'm honestly unfamiliar with objcopy variants and their quality/reliability.
3) A bug in the llvm-objcopy or CLANGDWARF tools_def commands on the edk2 side of things.
Some may disagree, but I would reduce 3) to either 1) or 2). I think even if the commands malformed and this causes the overflow, I believe LLD or objcopy should issue a warning regardless.
As I have no way to reproduce the issue, I cannot really help further, sorry.
Best regards,
Marvin
[1]
https://github.com/tianocore/edk2/blob/b08a19eae28e76fb5a296a604c27d06fab29b08a/UefiPayloadPkg/UniversalPayloadBuild.py#L163-L183
[2]
https://github.com/tianocore/edk2/blob/b08a19eae28e76fb5a296a604c27d06fab29b08a/BaseTools/Conf/build_rule.template#L298
[3]
https://github.com/tianocore/edk2/blob/b08a19eae28e76fb5a296a604c27d06fab29b08a/BaseTools/Conf/tools_def.template#L2895
https://github.com/tianocore/edk2/blob/b08a19eae28e76fb5a296a604c27d06fab29b08a/BaseTools/Conf/tools_def.template#L2931
>
>> -----Original Message-----
>> From: Patrick Rudolph <patrick.rudolph@9elements.com>
>> Sent: Friday, March 17, 2023 10:06 PM
>> Cc: devel@edk2.groups.io; Dong, Guo <guo.dong@intel.com>; Guo, Gua
>> <gua.guo@intel.com>; Lu, James <james.lu@intel.com>; Ni, Ray
>> <ray.ni@intel.com>; mhaeuser@posteo.de; ardb@kernel.org
>> Subject: [PATCH 2/3] BaseTools/Conf/tools_def: Fix
>> CLANGDWARF_IA32_X64
>>
>> Drop the "-z max-page-size=0x40" option as it causes the ELF
>> header to overflow into the .text section, causing undefined
>> behaviour.
>>
>> With high optimization level it corrupts essential code and
>> the binary would crash. It might work with low optimization
>> level though. As the default is to use Oz and LTO, it always
>> crashes.
>>
>> Test:
>> The ELF generated by
>> 'python UefiPayloadPkg/UniversalPayloadBuild.py -a IA32' boots.
>>
>> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
>> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4357
>> ---
>> BaseTools/Conf/tools_def.template | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/BaseTools/Conf/tools_def.template
>> b/BaseTools/Conf/tools_def.template
>> index 9b59bd75c3..0c584ab390 100755
>> --- a/BaseTools/Conf/tools_def.template
>> +++ b/BaseTools/Conf/tools_def.template
>> @@ -2866,7 +2866,7 @@ DEFINE CLANGDWARF_X64_PREFIX =
>> ENV(CLANG_BIN)
>>
>>
>> # LLVM/CLANG doesn't support -n link option. So, it can't share the same
>> IA32_X64_DLINK_COMMON flag.
>>
>> # LLVM/CLANG doesn't support common page size. So, it can't share the
>> same GccBase.lds script.
>>
>> -DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-
>> sections -z max-page-size=0x40
>>
>> +DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--
>> gc-sections
>>
>> DEFINE CLANGDWARF_DLINK2_FLAGS_COMMON = -Wl,--
>> script=$(EDK_TOOLS_PATH)/Scripts/ClangBase.lds
>>
>> DEFINE CLANGDWARF_IA32_X64_ASLDLINK_FLAGS =
>> DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--
>> defsym=PECOFF_HEADER_SIZE=0
>> DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--
>> entry,ReferenceAcpiTable -u ReferenceAcpiTable
>>
>> DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS =
>> DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--
>> entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-
>> Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
>>
>> --
>> 2.39.1
>
[-- Attachment #2: Type: text/html, Size: 5560 bytes --]
next prev parent reply other threads:[~2023-03-31 14:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 14:06 [PATCH 1/3] BaseTools/Conf/tools_def: Fix linking using CLANGDWARF_IA32 Patrick Rudolph
2023-03-17 14:06 ` [PATCH 2/3] BaseTools/Conf/tools_def: Fix CLANGDWARF_IA32_X64 Patrick Rudolph
2023-03-26 19:39 ` [edk2-devel] " Sheng Lean Tan
[not found] ` <17500F66A352AD33.14179@groups.io>
2023-03-26 19:42 ` Sheng Lean Tan
2023-03-28 5:38 ` 回复: " gaoliming
2023-03-28 11:25 ` Marvin Häuser
2023-03-31 4:53 ` 回复: " gaoliming
2023-03-31 10:57 ` Marvin Häuser
2023-04-03 0:52 ` 回复: " gaoliming
2023-04-03 5:53 ` Patrick Rudolph
2023-03-31 14:41 ` Ni, Ray
2023-03-31 14:58 ` Marvin Häuser [this message]
2023-03-17 17:30 ` [edk2-devel] [PATCH 1/3] BaseTools/Conf/tools_def: Fix linking using CLANGDWARF_IA32 Rebecca Cran
2023-03-17 17:44 ` Marvin Häuser
2023-03-17 20:35 ` Rebecca Cran
[not found] ` <174D4F37D4EEDF26.23349@groups.io>
2023-03-23 14:43 ` Rebecca Cran
2023-03-23 14:51 ` Sheng Lean Tan
2023-03-26 19:35 ` Sheng Lean Tan
2023-03-28 5:42 ` 回复: " gaoliming
2023-03-30 7:30 ` Sheng Lean Tan
2023-03-30 8:04 ` Marvin Häuser
2023-03-30 9:47 ` Patrick Rudolph
2023-04-04 12:46 ` Sheng Lean Tan
2023-04-05 8:27 ` Sheng Lean Tan
-- strict thread matches above, loose matches on Subject: below --
2023-03-06 8:37 [PATCH 1/3] BaseTools/Conf/tools_def: Fix linking using CLANGDWARF_IA32_X64 Patrick Rudolph
2023-03-06 8:37 ` [PATCH 2/3] BaseTools/Conf/tools_def: Fix CLANGDWARF_IA32_X64 Patrick Rudolph
2023-03-06 8:39 ` Sean Rhodes
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=3FB3223E-3591-4B15-AE1F-757A88D86074@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