This is an archive of the discontinued LLVM Phabricator instance.

[X86] Clang option -fuse-init-array has no effect when generating for MCU target
ClosedPublic

Authored by AndreiGrischenko on Apr 26 2017, 9:15 AM.

Details

Summary

Our runtime for MCU X86 target supports .init_array section for globals that should be dynamically initialized.
But default Clang generates .ctors section and even if it has option -fuse-init-array, the option has no effect if set explicitly in a command-line.
The problem is in lack of -fuse-array-init option initialization in CodeGen

void
X86LinuxNaClTargetObjectFile::Initialize(MCContext &Ctx,

                                       const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray);

}

Diff Detail

Repository
rL LLVM

Event Timeline

Do you need a front-end test? Since the changes are in the backend, I think it's better to add the test to the backend (using llc).

Do you need a front-end test? Since the changes are in the backend, I think it's better to add the test to the backend (using llc).

Yes, changes are in the backend, but they fix interface between frontend and backend, that's why I need to check option -fuse-init-array using front-end. Using llc I cannot check these changes.

craig.topper edited edge metadata.May 4 2017, 8:26 AM

Should we add a test to test/CodeGen/X86/constructor.ll that test appears to have been modified when NAcl was added to the line you changed.

It looksl ike UseInitArray is connected to -use-ctors command line option to llc so we should be able to test this without a frontend test.

Thanks Craig for the good advice. You are right I can check llc with MCU triple using option -use-ctors. Please see updated patch.

This revision is now accepted and ready to land.May 7 2017, 7:32 PM
This revision was automatically updated to reflect the committed changes.