[PATCH 0/3] BaseTools GCC: pass CC flags to linker


Ard Biesheuvel
 

GCC5 runs in LTO mode, which means it may generate code during the link
stage, and this code generation should be subject to the same settings
as ordinary code generation.

Since we now invoke GCC as the linker, we can start passing the CC_FLAGS
to the linker as well, with only minor surgery. This does not bother
non-LTO links at all, and forces the LTO links to use the correct settings.

Ard Biesheuvel (3):
BaseTools GCC: move -c compiler flag to build rules
BaseTools GCC5: disable warnings-as-errors for now
BaseTools GCC: add the compiler flags to the linker command line

BaseTools/Conf/build_rule.template | 18 ++++++++++--------
BaseTools/Conf/tools_def.template | 18 +++++++++---------
2 files changed, 19 insertions(+), 17 deletions(-)

--
2.7.4


Liming Gao
 

Ard:
Without this change, GCC5 LTO can pass build. With it, what difference will be in the generated image? Original way may generate the wrong image, or new way will generate the smaller image?

Thanks
Liming

-----Original Message-----
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
Sent: Tuesday, August 2, 2016 10:39 PM
To: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org
Cc: sigmaepsilon92@gmail.com; Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH 0/3] BaseTools GCC: pass CC flags to linker

GCC5 runs in LTO mode, which means it may generate code during the link
stage, and this code generation should be subject to the same settings
as ordinary code generation.

Since we now invoke GCC as the linker, we can start passing the CC_FLAGS
to the linker as well, with only minor surgery. This does not bother
non-LTO links at all, and forces the LTO links to use the correct settings.

Ard Biesheuvel (3):
BaseTools GCC: move -c compiler flag to build rules
BaseTools GCC5: disable warnings-as-errors for now
BaseTools GCC: add the compiler flags to the linker command line

BaseTools/Conf/build_rule.template | 18 ++++++++++--------
BaseTools/Conf/tools_def.template | 18 +++++++++---------
2 files changed, 19 insertions(+), 17 deletions(-)

--
2.7.4


Ard Biesheuvel
 

On 2 August 2016 at 16:50, Gao, Liming <liming.gao@intel.com> wrote:
Ard:
Without this change, GCC5 LTO can pass build. With it, what difference will be in the generated image? Original way may generate the wrong image, or new way will generate the smaller image?
This is not about code size but about correctness. Compiler switches
for code model or alignment etc may affect the way code is generated
at link time by the LTO routines.


Ard Biesheuvel
 

On 2 August 2016 at 16:51, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
On 2 August 2016 at 16:50, Gao, Liming <liming.gao@intel.com> wrote:
Ard:
Without this change, GCC5 LTO can pass build. With it, what difference will be in the generated image? Original way may generate the wrong image, or new way will generate the smaller image?
This is not about code size but about correctness. Compiler switches
for code model or alignment etc may affect the way code is generated
at link time by the LTO routines.
Note that Steven mentions a similar problem in his CLANG38 series: he
needs to pass -pie to the linker (or -fpie would be sufficient, I
suspect) to prevent the linker from using the wrong code model when
generating code from the LTO bytecode.

Thanks,
Ard.


Liming Gao
 

Ard:
I see Steven says it doesn't work, yet. So, I am curious what real issue is resolved by this patch?

Thanks
Liming

-----Original Message-----
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
Sent: Wednesday, August 03, 2016 4:23 PM
To: Gao, Liming <liming.gao@intel.com>
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Justen, Jordan L
<jordan.l.justen@intel.com>; edk2-devel@lists.01.org;
leif.lindholm@linaro.org; sigmaepsilon92@gmail.com
Subject: Re: [PATCH 0/3] BaseTools GCC: pass CC flags to linker

On 2 August 2016 at 16:51, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:
On 2 August 2016 at 16:50, Gao, Liming <liming.gao@intel.com> wrote:
Ard:
Without this change, GCC5 LTO can pass build. With it, what difference
will be in the generated image? Original way may generate the wrong image,
or new way will generate the smaller image?
This is not about code size but about correctness. Compiler switches
for code model or alignment etc may affect the way code is generated
at link time by the LTO routines.
Note that Steven mentions a similar problem in his CLANG38 series: he
needs to pass -pie to the linker (or -fpie would be sufficient, I
suspect) to prevent the linker from using the wrong code model when
generating code from the LTO bytecode.

Thanks,
Ard.


Ard Biesheuvel
 

On 3 August 2016 at 10:58, Gao, Liming <liming.gao@intel.com> wrote:
Ard:
I see Steven says it doesn't work, yet. So, I am curious what real issue is resolved by this patch?
For example, when building ArmVirtQemu for ARM, you may get warnings
(or errors when -Werror is enabled) like

lto1: warning: switch -mcpu=cortex-a15 conflicts with -march=armv7-a switch

where cortex-a15 is the target set by the platform .DSC, and armv7-a
is the default target of the compiler.
In this particular example, that does not cause any issues, since
cortex-a15 is compatible with armv7-a. However, if you are building
for ARM11, the code generation performed by the linker will generate
incompatible code unless we pass it the -mcpu=arm11 option as well.

The same applies to things like -mstrict-alignment and -mcmodel=xxx. I
suppose the same issue exists for IA32, where the -march/-mcpu options
in the platform may deviate from the compiler's default.

--
Ard.


Liming Gao
 

Ard:
Thanks for your detail explain. I understand it. I add my rb for this patch set.


Reviewed-by: Liming Gao <liming.gao@intel.com<mailto:liming.gao@intel.com>>

Thanks
Liming
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
Sent: Wednesday, August 3, 2016 5:24 PM
To: Gao, Liming <liming.gao@intel.com>
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org; sigmaepsilon92@gmail.com
Subject: Re: [PATCH 0/3] BaseTools GCC: pass CC flags to linker

On 3 August 2016 at 10:58, Gao, Liming wrote:
Ard:
I see Steven says it doesn't work, yet. So, I am curious what real issue is resolved by this patch?
For example, when building ArmVirtQemu for ARM, you may get warnings
(or errors when -Werror is enabled) like

lto1: warning: switch -mcpu=cortex-a15 conflicts with -march=armv7-a switch

where cortex-a15 is the target set by the platform .DSC, and armv7-a
is the default target of the compiler.
In this particular example, that does not cause any issues, since
cortex-a15 is compatible with armv7-a. However, if you are building
for ARM11, the code generation performed by the linker will generate
incompatible code unless we pass it the -mcpu=arm11 option as well.

The same applies to things like -mstrict-alignment and -mcmodel=xxx. I
suppose the same issue exists for IA32, where the -march/-mcpu options
in the platform may deviate from the compiler's default.

--
Ard.


Ard Biesheuvel
 

On 3 August 2016 at 15:20, Gao, Liming <liming.gao@intel.com> wrote:
Ard:

Thanks for your detail explain. I understand it. I add my rb for this
patch set.



Reviewed-by: Liming Gao <liming.gao@intel.com>
Pushed as

108c5b601860 BaseTools GCC: move -c compiler flag to build rules
f8d0b9662993 BaseTools GCC5: disable warnings-as-errors for now
478f50990a9a BaseTools GCC: add the compiler flags to the linker command line

with the simplification suggested by Leif regarding RVCT

Thanks,
Ard.