This is an archive of the discontinued LLVM Phabricator instance.

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

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

Details

Summary

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

Repository
rC Clang

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
lib/Driver/ToolChains/Clang.cpp
3670

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.
lib/Driver/ToolChains/Clang.cpp
3670

-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)) {
  CC1Args.push_back("-target-feature");
  CC1Args.push_back("+reserved-r19");
}
if (isAutoHVXEnabled(DriverArgs)) {
  CC1Args.push_back("-mllvm");
  CC1Args.push_back("-hexagon-autohvx");
}

}

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())
  CC1Args.push_back("-D_REENTRANT");

}

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.