Page MenuHomePhabricator

[Driver] Render target options (e.g. -fuse-init-array) for -fembed-bitcode

Authored by MaskRay on May 27 2019, 9:50 PM.



Modern ELF platforms use -fuse-init-array to emit .init_array instead of
.ctors . ld.bfd and gold --ctors-in-init-array merge .init_array and
.ctors into .init_array but lld doesn't do that.

If crtbegin*.o crtend*.o don't provide .ctors/.dtors, such .ctors in
user object files can lead to crash (see PR42002. The first and the last
elements in .ctors/.dtors are ignored - they are traditionally provided
by crtbegin*.o crtend*.o).

Call addClangTargetOptions() to ensure -fuse-init-array is rendered on
modern ELF platforms. On Hexagon, this renders -target-feature
+reserved-r19 for -ffixed-r19.

Diff Detail

Event Timeline

MaskRay created this revision.May 27 2019, 9:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2019, 9:50 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
compnerd added inline comments.May 28 2019, 5:15 PM

Hmm, what other arguments will this render into the option handling that we weren't handling before?

MaskRay marked an inline comment as done.May 28 2019, 6:49 PM
MaskRay added inline comments.

-fuse-init-array is the only one on Linux x86. Other OSes/targets may have more, e.g. Hexagon has:

void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs,

                                           ArgStringList &CC1Args,
                                           Action::OffloadKind) const {
if (DriverArgs.hasArg(options::OPT_ffixed_r19)) {
if (isAutoHVXEnabled(DriverArgs)) {


NetBSD has a -D (it should not matter):

void NetBSD::addClangTargetOptions(const ArgList &,

                                 ArgStringList &CC1Args,
                                 Action::OffloadKind) const {
const SanitizerArgs &SanArgs = getSanitizerArgs();
if (SanArgs.hasAnySanitizer())


compnerd accepted this revision.May 29 2019, 9:20 AM

Sounds safe enough to me. I think that it would be nice to add a test that checks the hexagon flags as well.

This revision is now accepted and ready to land.May 29 2019, 9:20 AM
MaskRay updated this revision to Diff 202103.May 29 2019, 7:24 PM
MaskRay retitled this revision from [Driver] Render -fuse-init-array for -fembed-bitcode to [Driver] Render target options (e.g. -fuse-init-array) for -fembed-bitcode.
MaskRay edited the summary of this revision. (Show Details)

Add hexagon test

This revision was automatically updated to reflect the committed changes.