This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use init_array instead of ctors for RISCV target, by default
ClosedPublic

Authored by mgrang on Mar 21 2018, 12:14 PM.

Details

Summary

LLVM defaults to the newer .init_array/.fini_array scheme for static
constructors rather than the less desirable .ctors/.dtors (the UseCtors
flag defaults to false). This wasn't being respected in the RISC-V
backend because it fails to call TargetLoweringObjectFileELF::InitializeELF with the the appropriate
flag for UseInitArray.
This patch fixes this by implementing RISCVELFTargetObjectFile and overriding its Initialize method to call
InitializeELF(TM.Options.UseInitArray).

Diff Detail

Repository
rL LLVM

Event Timeline

mgrang created this revision.Mar 21 2018, 12:14 PM
asb accepted this revision.Mar 22 2018, 3:39 AM

Hi Mandeep, thanks for the patch. This looks good to me, but there are just two changes I would suggest prior to committing:

  • Basing the test on test/CodeGen/Hexagon/ctor.ll would be better - that demonstrates that the -use-ctors flag is respected, which seems worth doing
  • The patch description explains what was changed, but not how or why. I might add something like "LLVM defaults to the newer .init_array/.fini_array scheme for static constructors rather than the less desirable .ctors/.dtors (the UseCtors flag defaults to false). This wasn't being respected in the RISC-V backend because it fails to call TargetLoweringObjectFileELF::InitializeELF with the the appropriate flag for UseInitArray. This patch fixes this by implementing RISCVELFTargetObjectFile and overriding its Initialize method to call InitializeELF(TM.Options.UseInitArray)."
This revision is now accepted and ready to land.Mar 22 2018, 3:39 AM
mgrang updated this revision to Diff 139490.Mar 22 2018, 12:06 PM
mgrang edited the summary of this revision. (Show Details)

Updated test.

This revision was automatically updated to reflect the committed changes.