This is an archive of the discontinued LLVM Phabricator instance.

[mips] Implement -muninit-const-in-rodata
ClosedPublic

Authored by sdardis on Jul 26 2017, 2:32 PM.

Details

Summary

This option when combined with -mgpopt and -membedded-data places all
uninitialized constant variables in the read-only section.

Diff Detail

Repository
rL LLVM

Event Timeline

sdardis created this revision.Jul 26 2017, 2:32 PM
atanasyan added inline comments.Aug 3 2017, 5:39 AM
include/clang/Driver/Options.td
2065 ↗(On Diff #108359)

s/Place/place/

lib/Driver/ToolChains/Clang.cpp
1523 ↗(On Diff #108359)

What's happened if the -muninit-const-in-rodata is used without -membedded-data? Will the compiler shows a warning about unused command line option?

sdardis updated this revision to Diff 109545.Aug 3 2017, 6:45 AM
sdardis marked an inline comment as done.

Address review comment.

lib/Driver/ToolChains/Clang.cpp
1523 ↗(On Diff #108359)

Yes, it warns that it's unused.

This revision is now accepted and ready to land.Aug 3 2017, 6:47 AM
This revision was automatically updated to reflect the committed changes.

Thanks for the reviews of all of these options.

Do you actually need a new flag for this? "-fno-common" will ensure clang doesn't generate globals with common linkage.

efriedma added inline comments.Aug 3 2017, 11:51 AM
cfe/trunk/lib/CodeGen/TargetInfo.cpp
6666

Also, this change is clearly unacceptable; among other things, messing with the linkage of static local variables is likely to lead to link errors.

It's required for feature parity with GCC.

-fno-common will place globals into the bss section which uses memory at runtime. The -membedded-data and -muninit-const-in-rodata options are for reducing RAM usage in some embedded environments.

LLVM never puts constant data into the BSS. See isSuitableForBSS in lib/Target/TargetLoweringObjectFile.cpp.

(gcc's behavior is just weird... apparently, whether or not constant data is placed in the BSS with -fno-common depends on the syntactic form of the initializer?)

sdardis added inline comments.Aug 3 2017, 12:05 PM
cfe/trunk/lib/CodeGen/TargetInfo.cpp
6666

I will fix that.

joerg added a subscriber: joerg.Aug 3 2017, 12:07 PM

I don't see any reason why zero-initialised constants should be emitted in BSS. I know that GCC does that and I just fixed bugs in that because created wrong section flags for it. So yes, I'd prefer to revert this and fix the real problem.

I don't see any reason why zero-initialised constants should be emitted in BSS. I know that GCC does that and I just fixed bugs in that because created wrong section flags for it. So yes, I'd prefer to revert this and fix the real problem.

Will do.