From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, christopher.j.zurcher@intel.com, "Yao,
Jiewen" <jiewen.yao@intel.com>,
"Jiang, Guomin" <guomin.jiang@intel.com>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>,
"Lu, XiaoyuX" <xiaoyux.lu@intel.com>,
"Ard Biesheuvel (ARM address)" <ard.biesheuvel@arm.com>
Subject: Re: [edk2-devel] [PATCH v2 1/2] CryptoPkg/OpensslLib: Add native instruction support for X64
Date: Thu, 1 Oct 2020 14:58:10 +0200 [thread overview]
Message-ID: <1ce6123c-7616-30ad-07a0-30b6a5b51dec@redhat.com> (raw)
In-Reply-To: <MWHPR1101MB2125A1E5409DB4ABC54DB554B3320@MWHPR1101MB2125.namprd11.prod.outlook.com>
(refreshing Ard's address, comments below)
On 09/29/20 23:08, Zurcher, Christopher J wrote:
> The GCC build fails with this error:
>
> `OPENSSL_ia32cap_P' referenced in section `.text.OPENSSL_cpuid_setup'
> of /tmp/ccIIRAYs.ltrans20.ltrans.o: defined in discarded section
> `COMMON' of
> /mnt/c/mssql/tiano/Build/OvmfX64/DEBUG_GCC5/X64/CryptoPkg/Library/OpensslLib/OpensslLibX64/OUTPUT/OpensslLibX64.lib(x86_64cpuid.obj)
>
> The code in question is here:
>> section .CRT$XCU rdata align=8
>> DQ OPENSSL_cpuid_setup
>>
>> common OPENSSL_ia32cap_P 16
For the X64 arch, OPENSSL_cpuid_setup() is implemented in
CryptoPkg/Library/OpensslLib/openssl/crypto/cryptlib.c
It makes references to:
extern unsigned int OPENSSL_ia32cap_P[4];
The variable is defined in generated assembly source code.
There seem to be multiple generators (for various assemblers):
(1) crypto/perlasm/x86gas.pl -- likely for the GNU assembler:
> my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,16";
(2) crypto/perlasm/x86nasm.pl -- likely for NASM:
> ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 16
(3) crypto/x86_64cpuid.pl -- likely for... ???
> .comm OPENSSL_ia32cap_P,16,4
They all put the variable in the "common" section.
Tracking the NASM generator through a number of "git blame" commands,
I've ended up at historical commit 10e7d6d52650 ("Support for IA-32 SSE2
instruction set.", 2004-05-06). This commit introduced "OPENSSL_ia32cap"
at once in the common section -- see "crypto/perlasm/x86unix.pl".
Now, the NASM manual says the following about the common section:
> 6.7. 'COMMON': Defining Common Data Areas
> =========================================
>
> The 'COMMON' directive is used to declare _common variables_. A common
> variable is much like a global variable declared in the uninitialized
> data section, so that
>
> common intvar 4
>
> is similar in function to
>
> global intvar
> section .bss
>
> intvar resd 1
>
> The difference is that if more than one module defines the same
> common variable, then at link time those variables will be _merged_, and
> references to 'intvar' in all modules will point at the same piece of
> memory.
The common section is a *really* bad idea for C language projects,
because if there are multiple external definitions of an object in a
program, then that should (per C language standard) prevent the
successful linking of the program, rather than undergo silent definition
merging.
This has caused actual, inexplicable bugs in edk2 -- identically named,
but differently sized, and entirely independently inteded, variables
with external linkage and static storage duration got silently merged,
rather than breaking the build. In the end, we tracked those down and
marked them all STATIC. But in order to prevent such nonsense in the
future, we also forbade the common section altogether. Let me find that
commit...
Yes, please see 214a3b79417f ("BaseTools GCC: avoid the use of COMMON
symbols", 2015-12-08).
So, my guess is that this interferes with OpenSSL's placing of
"OPENSSL_ia32cap_P" in the common section.
Without knowing more, I'd hazard that this is a bug in OpenSSL. Unless
they have a strong reason for it, I think we should try to contribute a
patch that removes "common".
The code should provide exactly one definition (in the generated
assembly source), provide one central (extern) declaration too, in a
header file, then let all users include the declaration via the header
file. The object file built from the generated assembly source should be
linked into each final executable.
For example, "CryptoPkg/Library/OpensslLib/openssl/crypto/cryptlib.c"
already correctly declares the variable as "extern".
Otherwise, as last resort, I guess we could attempt working it around by
adding back "-fcommon" to the OpensslLib build flags. :/
Thanks,
Laszlo
next prev parent reply other threads:[~2020-10-01 12:58 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-04 0:24 [PATCH v2 0/2] CryptoPkg/OpensslLib: Add native instruction support for X64 Zurcher, Christopher J
2020-08-04 0:24 ` [PATCH v2 1/2] " Zurcher, Christopher J
2020-08-11 11:46 ` [edk2-devel] " Guomin Jiang
2020-08-13 15:03 ` Yao, Jiewen
2020-08-18 22:49 ` Zurcher, Christopher J
[not found] ` <162C7E6ED8CEF542.12673@groups.io>
2020-08-24 21:25 ` [edk2-devel] " Zurcher, Christopher J
2020-08-24 23:35 ` Yao, Jiewen
2020-09-16 9:17 ` Guomin Jiang
2020-09-22 15:21 ` Zurcher, Christopher J
2020-09-23 2:35 ` Yao, Jiewen
2020-09-25 0:28 ` Zurcher, Christopher J
2020-09-25 0:49 ` 回复: " gaoliming
2020-09-25 1:06 ` Zurcher, Christopher J
2020-09-25 1:11 ` Yao, Jiewen
2020-09-25 1:14 ` Zurcher, Christopher J
[not found] ` <1637E1D4851CF309.11037@groups.io>
2020-09-25 2:28 ` Zurcher, Christopher J
[not found] ` <1637E5DD452A46F1.2312@groups.io>
2020-09-25 8:01 ` Zurcher, Christopher J
2020-09-29 21:08 ` Zurcher, Christopher J
2020-10-01 12:58 ` Laszlo Ersek [this message]
2020-10-08 19:56 ` Zurcher, Christopher J
2020-10-09 11:37 ` Laszlo Ersek
2020-10-09 19:27 ` Zurcher, Christopher J
2020-10-15 7:14 ` Laszlo Ersek
2020-08-04 0:24 ` [PATCH v2 2/2] CryptoPkg/OpensslLib: Commit the auto-generated assembly files " Zurcher, Christopher J
2020-08-13 15:24 ` Yao, Jiewen
2020-08-13 15:37 ` Michael D Kinney
2020-08-13 15:45 ` Yao, Jiewen
2020-08-14 19:34 ` Zurcher, Christopher J
2020-08-18 2:36 ` Wang, Jian J
2020-08-18 16:15 ` Michael D Kinney
2020-08-18 21:33 ` [edk2-devel] " Sean
2020-08-18 23:29 ` Andrew Fish
2020-08-19 16:33 ` Liming Gao
2020-08-19 10:43 ` Laszlo Ersek
2020-08-19 16:08 ` Michael D Kinney
2020-08-19 17:21 ` Laszlo Ersek
2020-08-18 16:15 ` Michael D Kinney
2020-08-18 21:22 ` Zurcher, Christopher J
2020-08-19 15:37 ` [edk2-devel] " Andrew Fish
2020-08-19 18:06 ` Laszlo Ersek
2020-08-25 0:55 ` Andrew Fish
2020-08-26 10:05 ` Laszlo Ersek
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=1ce6123c-7616-30ad-07a0-30b6a5b51dec@redhat.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