public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zurcher, Christopher J" <christopher.j.zurcher@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"lersek@redhat.com" <lersek@redhat.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: Fri, 9 Oct 2020 19:27:33 +0000	[thread overview]
Message-ID: <MWHPR1101MB2125C8E39FE4AA075669BC97B3080@MWHPR1101MB2125.namprd11.prod.outlook.com> (raw)
In-Reply-To: <18e31a95-85e4-9c76-bdc1-5ffa0d32d9cd@redhat.com>

Here is the error message:
[...]/OpensslLibX64/OUTPUT/X64/crypto/aes/aesni-mb-x86_64.iii:1746: error: symbol `..imagebase' undefined
[cut 18 lines]
[...]/OpensslLibX64/OUTPUT/X64/crypto/aes/aesni-mb-x86_64.iii:1775: error: symbol `..imagebase' undefined
GNUmakefile:3390: recipe for target '[...]OpensslLibX64/OUTPUT/X64/crypto/aes/aesni-mb-x86_64.obj' failed
make: *** [[...]/OpensslLibX64/OUTPUT/X64/crypto/aes/aesni-mb-x86_64.obj] Error 1

The functionality is described here in "7.6.1 win64: Writing Position-Independent Code" and "7.6.2 win64: Structured Exception Handling"
https://www.nasm.us/xdoc/2.13.02rc3/html/nasmdoc7.html

The x86_64 implementation in OpenSSL seems to assume that building with NASM guarantees a Windows toolchain and Windows execution environment.

Thanks,
Christopher Zurcher

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Laszlo Ersek
> Sent: Friday, October 9, 2020 04:37
> To: Zurcher, Christopher J <christopher.j.zurcher@intel.com>;
> devel@edk2.groups.io; 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
> 
> On 10/08/20 21:56, Zurcher, Christopher J wrote:
> > Laszlo, thanks for sharing this explanation and history. I have found that
> in addition to the "common" declaration, OpenSSL's Structured Exception
> Handling functionality also breaks the GCC build by including "wrt
> ..imagebase" statements. Since we cannot implement functional changes in the
> current 1.1.1x versions of OpenSSL, my proposal is to go ahead with this
> patch only supporting VS and LLVM toolchains for now.
> 
> Could you include the error message with the "wrt ..imagebase" string?
> 
> I found the string in "crypto/perlasm/x86_64-xlate.pl" but don't really
> understand what it's about.
> 
> I'd just like us to make one attempt to resolve that problem; otherwise
> personally I'm OK if this new feature is not enabled for GCC at first.
> 
> Thanks
> Laszlo
> 
> >
> > Thanks,
> > Christopher Zurcher
> >
> >> -----Original Message-----
> >> From: Laszlo Ersek <lersek@redhat.com>
> >> Sent: Thursday, October 1, 2020 05:58
> >> To: devel@edk2.groups.io; Zurcher, Christopher J
> >> <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
> >>
> >> (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
> >
> 
> 
> 
> 
> 


  reply	other threads:[~2020-10-09 19:27 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
2020-10-08 19:56                     ` Zurcher, Christopher J
2020-10-09 11:37                       ` Laszlo Ersek
2020-10-09 19:27                         ` Zurcher, Christopher J [this message]
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=MWHPR1101MB2125C8E39FE4AA075669BC97B3080@MWHPR1101MB2125.namprd11.prod.outlook.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