[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-14 Thread Jason Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf85bcc21ddad: [AIX] Turn -fdata-sections on by default in 
Clang (authored by jasonliu).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D88737?vs=296965&id=298160#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-data-sections.c
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/Common/TargetOptionsCommandFlags.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/test/CodeGen/PowerPC/aix-alias.ll
  llvm/test/CodeGen/PowerPC/aix-bytestring.ll
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-extern.ll
  llvm/test/CodeGen/PowerPC/aix-ignore-xcoff-visibility.ll
  llvm/test/CodeGen/PowerPC/aix-overflow-toc.py
  llvm/test/CodeGen/PowerPC/aix-readonly-with-relocation.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
  llvm/test/CodeGen/PowerPC/aix-return55.ll
  llvm/test/CodeGen/PowerPC/aix-weak.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -698,7 +698,8 @@
   Triple ModuleTriple(M->getTargetTriple());
   std::string CPUStr, FeaturesStr;
   TargetMachine *Machine = nullptr;
-  const TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  const TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
 
   if (ModuleTriple.getArch()) {
 CPUStr = codegen::getCPUStr();
Index: llvm/tools/lto/lto.cpp
===
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -218,7 +218,8 @@
 
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromFile(*LTOContext, StringRef(path), Options);
   if (!M)
@@ -228,7 +229,8 @@
 
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFile(
   *LTOContext, fd, StringRef(path), size, Options);
   if (!M)
@@ -241,7 +243,8 @@
  size_t map_size,
  off_t offset) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFileSlice(
   *LTOContext, fd, StringRef(path), map_size, offset, Options);
   if (!M)
@@ -251,7 +254,8 @@
 
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromBuffer(*LTOContext, mem, length, Options);
   if (!M)
@@ -263,7 +267,8 @@
  size_t length,
  const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromBuffer(
   *LTOContext, mem, length, Options, StringRef(path));
   if (!M)
@@ -274,7 +279,8 @@
 lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
  

[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-13 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added a comment.

Hi Fangrui(@MaskRay), are you okay with this patch to land as is?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-09 Thread Digger via Phabricator via cfe-commits
DiggerLin added a comment.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-09 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added a comment.

In D88737#2321921 , @MaskRay wrote:

> A less intrusive approach is to not touch the existing 
> InitTargetOptionsFromCodeGenFlags without parameters. You can add an 
> `initTargetOptionsFromCodeGenFlags` with `const Tripe &` as its parameter.

I thought about that. But would prefer people think about whether or not a 
proper Triple is actually needed in that scenario before they make a call to 
`InitTargetOptionsFromCodeGenFlags`. 
Have an `InitTargetOptionsFromCodeGenFlags` without parameter, or has Triple() 
as default parameter could potentially results in people choose the wrong one 
to call because it's just more convenient.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

A less intrusive approach is to not touch the existing 
InitTargetOptionsFromCodeGenFlags without parameters. You can add an 
`initTargetOptionsFromCodeGenFlags` with `const Tripe &` as its parameter.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-08 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: lld/Common/TargetOptionsCommandFlags.cpp:17
+llvm::TargetOptions
+lld::initTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple) {
+  return llvm::codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);

MaskRay wrote:
> jasonliu wrote:
> > MaskRay wrote:
> > > Currently lld does not need Triple. Consider not changing the signature 
> > > of `initTargetOptionsFromCodeGenFlags`.
> > This function acts like a forwarder for 
> > llvm::codegen::InitTargetOptionsFromCodeGenFlags.
> > I think it still makes sense to change the signature in this case to 
> > minimize the different variation of the function, as those variations cause 
> > confusion to people. 
> > I will change the name to match the LLVM style.
> If you want to change `InitTargetOptionsFromCodeGenFlags` in an incompatible 
> way, you can by the way rename it to `initTarget*`.
> 
> lld functions should always stick with the `camelCase` rule. If there is no 
> meaningful triple, I'd prefer leave out the parameter.
Sorry, didn't realize lld has this `camelCase` rule. 
I don't have a better naming for it, so I will just leave the function 
signature untouched. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-08 Thread Jason Liu via Phabricator via cfe-commits
jasonliu updated this revision to Diff 296965.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-data-sections.c
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/Common/TargetOptionsCommandFlags.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/test/CodeGen/PowerPC/aix-alias.ll
  llvm/test/CodeGen/PowerPC/aix-bytestring.ll
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-extern.ll
  llvm/test/CodeGen/PowerPC/aix-overflow-toc.py
  llvm/test/CodeGen/PowerPC/aix-readonly-with-relocation.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
  llvm/test/CodeGen/PowerPC/aix-return55.ll
  llvm/test/CodeGen/PowerPC/aix-weak.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -698,7 +698,8 @@
   Triple ModuleTriple(M->getTargetTriple());
   std::string CPUStr, FeaturesStr;
   TargetMachine *Machine = nullptr;
-  const TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  const TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
 
   if (ModuleTriple.getArch()) {
 CPUStr = codegen::getCPUStr();
Index: llvm/tools/lto/lto.cpp
===
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -218,7 +218,8 @@
 
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromFile(*LTOContext, StringRef(path), Options);
   if (!M)
@@ -228,7 +229,8 @@
 
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFile(
   *LTOContext, fd, StringRef(path), size, Options);
   if (!M)
@@ -241,7 +243,8 @@
  size_t map_size,
  off_t offset) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFileSlice(
   *LTOContext, fd, StringRef(path), map_size, offset, Options);
   if (!M)
@@ -251,7 +254,8 @@
 
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromBuffer(*LTOContext, mem, length, Options);
   if (!M)
@@ -263,7 +267,8 @@
  size_t length,
  const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromBuffer(
   *LTOContext, mem, length, Options, StringRef(path));
   if (!M)
@@ -274,7 +279,8 @@
 lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
 const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
 
   // Create a local context. Ownership will be transferred to LTOModule.
   std::unique_ptr Context = std::make_unique();
@@

[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lld/Common/TargetOptionsCommandFlags.cpp:17
+llvm::TargetOptions
+lld::initTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple) {
+  return llvm::codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);

jasonliu wrote:
> MaskRay wrote:
> > Currently lld does not need Triple. Consider not changing the signature of 
> > `initTargetOptionsFromCodeGenFlags`.
> This function acts like a forwarder for 
> llvm::codegen::InitTargetOptionsFromCodeGenFlags.
> I think it still makes sense to change the signature in this case to minimize 
> the different variation of the function, as those variations cause confusion 
> to people. 
> I will change the name to match the LLVM style.
If you want to change `InitTargetOptionsFromCodeGenFlags` in an incompatible 
way, you can by the way rename it to `initTarget*`.

lld functions should always stick with the `camelCase` rule. If there is no 
meaningful triple, I'd prefer leave out the parameter.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-07 Thread Jason Liu via Phabricator via cfe-commits
jasonliu updated this revision to Diff 296665.
jasonliu added a comment.

Change lld's forwarder function's signature to match LLVM style.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-data-sections.c
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/COFF/LTO.cpp
  lld/Common/TargetOptionsCommandFlags.cpp
  lld/ELF/LTO.cpp
  lld/include/lld/Common/TargetOptionsCommandFlags.h
  lld/wasm/LTO.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/test/CodeGen/PowerPC/aix-alias.ll
  llvm/test/CodeGen/PowerPC/aix-bytestring.ll
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-extern.ll
  llvm/test/CodeGen/PowerPC/aix-overflow-toc.py
  llvm/test/CodeGen/PowerPC/aix-readonly-with-relocation.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
  llvm/test/CodeGen/PowerPC/aix-return55.ll
  llvm/test/CodeGen/PowerPC/aix-weak.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -698,7 +698,8 @@
   Triple ModuleTriple(M->getTargetTriple());
   std::string CPUStr, FeaturesStr;
   TargetMachine *Machine = nullptr;
-  const TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  const TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
 
   if (ModuleTriple.getArch()) {
 CPUStr = codegen::getCPUStr();
Index: llvm/tools/lto/lto.cpp
===
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -218,7 +218,8 @@
 
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromFile(*LTOContext, StringRef(path), Options);
   if (!M)
@@ -228,7 +229,8 @@
 
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFile(
   *LTOContext, fd, StringRef(path), size, Options);
   if (!M)
@@ -241,7 +243,8 @@
  size_t map_size,
  off_t offset) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFileSlice(
   *LTOContext, fd, StringRef(path), map_size, offset, Options);
   if (!M)
@@ -251,7 +254,8 @@
 
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromBuffer(*LTOContext, mem, length, Options);
   if (!M)
@@ -263,7 +267,8 @@
  size_t length,
  const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromBuffer(
   *LTOContext, mem, length, Options, StringRef(path));
   if (!M)
@@ -274,7 +279,8 @@
 lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
 const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOpti

[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-07 Thread Jason Liu via Phabricator via cfe-commits
jasonliu marked an inline comment as done.
jasonliu added inline comments.



Comment at: clang/test/Driver/aix-data-sections.c:7
+// RUN:   | FileCheck %s
+// CHECK: "-fdata-sections"

DiggerLin wrote:
> may be good to check the whether other OS platform behavior be changed or 
> not? 
I think there are existing lit tests checked other platform's behavior.

linux platform behavior is tested in clang/test/Driver/function-sections.c
cloudABI platform behavior is tested in clang/test/Driver/cloudabi.c
msvc behavior is tested in clang/test/Driver/cl-options.c



Comment at: lld/Common/TargetOptionsCommandFlags.cpp:17
+llvm::TargetOptions
+lld::initTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple) {
+  return llvm::codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);

MaskRay wrote:
> Currently lld does not need Triple. Consider not changing the signature of 
> `initTargetOptionsFromCodeGenFlags`.
This function acts like a forwarder for 
llvm::codegen::InitTargetOptionsFromCodeGenFlags.
I think it still makes sense to change the signature in this case to minimize 
the different variation of the function, as those variations cause confusion to 
people. 
I will change the name to match the LLVM style.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-06 Thread Digger via Phabricator via cfe-commits
DiggerLin added inline comments.



Comment at: clang/test/Driver/aix-data-sections.c:7
+// RUN:   | FileCheck %s
+// CHECK: "-fdata-sections"

may be good to check the whether other OS platform behavior be changed or not? 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-05 Thread Digger via Phabricator via cfe-commits
DiggerLin added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:46
  ///< aliases to base ctors when possible.
-CODEGENOPT(DataSections  , 1, 0) ///< Set when -fdata-sections is enabled.
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.

DiggerLin wrote:
> turn on by default , it should be changed to CODEGENOPT(DataSections  , 
> 1, 1) ?
> 
please  ignore above comment.  DataSection is set by default only on AIX OS . 
the comment maybe need to be modified?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-05 Thread Digger via Phabricator via cfe-commits
DiggerLin added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:46
  ///< aliases to base ctors when possible.
-CODEGENOPT(DataSections  , 1, 0) ///< Set when -fdata-sections is enabled.
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.

turn on by default , it should be changed to CODEGENOPT(DataSections  , 1, 
1) ?



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lld/Common/TargetOptionsCommandFlags.cpp:17
+llvm::TargetOptions
+lld::initTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple) {
+  return llvm::codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);

Currently lld does not need Triple. Consider not changing the signature of 
`initTargetOptionsFromCodeGenFlags`.



Comment at: llvm/include/llvm/CodeGen/CommandFlags.h:142
+///passed in.
+TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple);
 

If you are going to change the signature, consider renaming it to 
InitTargetOptionsFromCodeGenFlags to be consistent with the coding standard.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Jason Liu via Phabricator via cfe-commits
jasonliu updated this revision to Diff 295950.
jasonliu added a comment.
Herald added subscribers: llvm-commits, nemanjai.
Herald added a project: LLVM.

An update follows up with the idea in D88748 .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-data-sections.c
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/COFF/LTO.cpp
  lld/Common/TargetOptionsCommandFlags.cpp
  lld/ELF/LTO.cpp
  lld/include/lld/Common/TargetOptionsCommandFlags.h
  lld/wasm/LTO.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/test/CodeGen/PowerPC/aix-alias.ll
  llvm/test/CodeGen/PowerPC/aix-bytestring.ll
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-extern.ll
  llvm/test/CodeGen/PowerPC/aix-overflow-toc.py
  llvm/test/CodeGen/PowerPC/aix-readonly-with-relocation.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
  llvm/test/CodeGen/PowerPC/aix-return55.ll
  llvm/test/CodeGen/PowerPC/aix-weak.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-symbol-rename.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-used.ll
  llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -698,7 +698,8 @@
   Triple ModuleTriple(M->getTargetTriple());
   std::string CPUStr, FeaturesStr;
   TargetMachine *Machine = nullptr;
-  const TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  const TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
 
   if (ModuleTriple.getArch()) {
 CPUStr = codegen::getCPUStr();
Index: llvm/tools/lto/lto.cpp
===
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -218,7 +218,8 @@
 
 lto_module_t lto_module_create(const char* path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromFile(*LTOContext, StringRef(path), Options);
   if (!M)
@@ -228,7 +229,8 @@
 
 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFile(
   *LTOContext, fd, StringRef(path), size, Options);
   if (!M)
@@ -241,7 +243,8 @@
  size_t map_size,
  off_t offset) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromOpenFileSlice(
   *LTOContext, fd, StringRef(path), map_size, offset, Options);
   if (!M)
@@ -251,7 +254,8 @@
 
 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M =
   LTOModule::createFromBuffer(*LTOContext, mem, length, Options);
   if (!M)
@@ -263,7 +267,8 @@
  size_t length,
  const char *path) {
   lto_initialize();
-  llvm::TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
+  llvm::TargetOptions Options =
+  codegen::InitTargetOptionsFromCodeGenFlags(Triple());
   ErrorOr> M = LTOModule::createFromBuffer(
   *LTOContext, mem, length, Options, StringRef(path));
   if (!M)
@@ -274,7 +279,8 @@
 lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
 const char *path) {
   lto_initialize();
-  

[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:47
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.

jasonliu wrote:
> jasonliu wrote:
> > MaskRay wrote:
> > > From the current code. I don't see HasExplicitDataSections is necessary. 
> > > Please remove the lld changes.
> > The reason I need `HasExplicitDataSections` goes back to D88493(which I 
> > haven't land yet, because I actually need to land these two patches 
> > together to avoid build break). In D88493, I'm trying to get the llc's 
> > default for -data-sections to be correct for AIX and introduced 
> > `HasExplicitDataSections`. If `HasExplicitDataSections` is not set, then 
> > llc would think there is -data-sections set, so it would just take the 
> > target triple's default, which makes `DataSections` setting to be useless. 
> > It seems there is no good way to set a certain TargetOption's default to be 
> > dependant on the current target triple. As I already mentioned in my own 
> > comment in this patch, one of the way to achieve that could be make 
> > DataSections an enum option in TargetOptions, so that it could have a 
> > `Default` enum which could mean true or false depending on the triple 
> > setting. But it could mean a bigger refactoring to this option. 
> Correction:
> If HasExplicitDataSections is not set, then llc would think there is **no** 
> -data-sections set, so it would just take the target triple's default...
D88748


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:47
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.

jasonliu wrote:
> MaskRay wrote:
> > From the current code. I don't see HasExplicitDataSections is necessary. 
> > Please remove the lld changes.
> The reason I need `HasExplicitDataSections` goes back to D88493(which I 
> haven't land yet, because I actually need to land these two patches together 
> to avoid build break). In D88493, I'm trying to get the llc's default for 
> -data-sections to be correct for AIX and introduced 
> `HasExplicitDataSections`. If `HasExplicitDataSections` is not set, then llc 
> would think there is -data-sections set, so it would just take the target 
> triple's default, which makes `DataSections` setting to be useless. 
> It seems there is no good way to set a certain TargetOption's default to be 
> dependant on the current target triple. As I already mentioned in my own 
> comment in this patch, one of the way to achieve that could be make 
> DataSections an enum option in TargetOptions, so that it could have a 
> `Default` enum which could mean true or false depending on the triple 
> setting. But it could mean a bigger refactoring to this option. 
Correction:
If HasExplicitDataSections is not set, then llc would think there is **no** 
-data-sections set, so it would just take the target triple's default...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:47
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.

MaskRay wrote:
> From the current code. I don't see HasExplicitDataSections is necessary. 
> Please remove the lld changes.
The reason I need `HasExplicitDataSections` goes back to D88493(which I haven't 
land yet, because I actually need to land these two patches together to avoid 
build break). In D88493, I'm trying to get the llc's default for -data-sections 
to be correct for AIX and introduced `HasExplicitDataSections`. If 
`HasExplicitDataSections` is not set, then llc would think there is 
-data-sections set, so it would just take the target triple's default, which 
makes `DataSections` setting to be useless. 
It seems there is no good way to set a certain TargetOption's default to be 
dependant on the current target triple. As I already mentioned in my own 
comment in this patch, one of the way to achieve that could be make 
DataSections an enum option in TargetOptions, so that it could have a `Default` 
enum which could mean true or false depending on the triple setting. But it 
could mean a bigger refactoring to this option. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added inline comments.
This revision now requires changes to proceed.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:47
+CODEGENOPT(DataSections  , 1, 0) ///< Set by default, or when 
-f[no-]data-sections.
+CODEGENOPT(HasExplicitDataSections, 1, 0) ///< Set when -f[no-]data-sections 
is set.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.

From the current code. I don't see HasExplicitDataSections is necessary. Please 
remove the lld changes.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4915
+  CmdArgs.push_back("-fno-data-sections");
+  } else if (UseSeparateSections) {
 CmdArgs.push_back("-fdata-sections");

You can place AIX in isUseSeparateSections instead.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:994
 
+  if (Args.getLastArg(OPT_fdata_sections) ||
+  Args.getLastArg(OPT_fno_data_sections)) {

In many cases, there is no need for having both positive and negative CC1 
options. The driver handles the default.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added a comment.

Not sure if there is a better way to do this. But I have to admit this approach 
along with D88493  is a bit fragile. 
If plug-in writer forgets to set `HasExplicitDataSections` to true, then the 
final result that TargetMachine give for `getDataSections()` could be false on 
most platform even when they deliberately set `DataSections` to true.
We have other targets in LLVM that have -fdata-sections by default as well. And 
they do it differently as well, which makes this a bit more complicate to be 
consistent. 
For example, cloudABI would pass -fdata-sections through the Clang Driver by 
default. But that approach means if some user just invoke llc directly, they 
could get the wrong default on llc for that platform. 
Wasm would just overwrite the `DataSections` option to true in their 
TargetMachine. But that means you could not set it to false even if you want to.
I've thought about making the `DataSections` option in TargetOptions an enum 
instead of boolean value, where you could have `Default`, `On` and `Off` to 
represent what we actually want for the options. That's not a trivial change, 
as a lot of consumers for TargetOptions are relying it to be a boolean.
If you think it's a better way to solve this problem and I should explore, let 
me know.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88737/new/

https://reviews.llvm.org/D88737

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88737: [AIX] Turn -fdata-sections on by default in Clang

2020-10-02 Thread Jason Liu via Phabricator via cfe-commits
jasonliu created this revision.
jasonliu added reviewers: hubert.reinterpretcast, daltenty, sfertile, 
Xiangling_L, DiggerLin.
Herald added subscribers: dang, dexonsmith, steven_wu, hiraditya, arichardson, 
sbc100, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: MaskRay.
jasonliu requested review of this revision.
Herald added a subscriber: aheejin.

This is the follow up on D88493  where we 
flipped the default for llc on AIX.
We would also want to flip the default for Clang as well.


https://reviews.llvm.org/D88737

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/function-sections.c
  lld/COFF/LTO.cpp
  lld/ELF/LTO.cpp
  lld/wasm/LTO.cpp

Index: lld/wasm/LTO.cpp
===
--- lld/wasm/LTO.cpp
+++ lld/wasm/LTO.cpp
@@ -45,6 +45,7 @@
 
   // Always emit a section per function/data with LTO.
   c.Options.FunctionSections = true;
+  c.Options.HasExplicitDataSections = true;
   c.Options.DataSections = true;
 
   c.DisableVerify = config->disableVerify;
Index: lld/ELF/LTO.cpp
===
--- lld/ELF/LTO.cpp
+++ lld/ELF/LTO.cpp
@@ -86,6 +86,7 @@
 
   // Always emit a section per function/datum with LTO.
   c.Options.FunctionSections = true;
+  c.Options.HasExplicitDataSections = true;
   c.Options.DataSections = true;
 
   // Check if basic block sections must be used.
Index: lld/COFF/LTO.cpp
===
--- lld/COFF/LTO.cpp
+++ lld/COFF/LTO.cpp
@@ -66,6 +66,7 @@
   // Always emit a section per function/datum with LTO. LLVM LTO should get most
   // of the benefit of linker GC, but there are still opportunities for ICF.
   c.Options.FunctionSections = true;
+  c.Options.HasExplicitDataSections = true;
   c.Options.DataSections = true;
 
   // Use static reloc model on 32-bit x86 because it usually results in more
Index: clang/test/Driver/function-sections.c
===
--- clang/test/Driver/function-sections.c
+++ clang/test/Driver/function-sections.c
@@ -3,13 +3,15 @@
 // CHECK-FS: -ffunction-sections
 // CHECK-NOFS-NOT: -ffunction-sections
 // CHECK-DS: -fdata-sections
-// CHECK-NODS-NOT: -fdata-sections
+// CHECK-NODS: -fno-data-sections
+// CHECK-DS-DEFAULT-NOT: -fdata-sections
+// CHECK-DS-DEFAULT-NOT: -fno-data-sections
 // CHECK-US-NOT: -fno-unique-section-names
 // CHECK-NOUS: -fno-unique-section-names
 
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1   \
 // RUN: -target i386-unknown-linux \
-// RUN:   | FileCheck --check-prefix=CHECK-NOFS --check-prefix=CHECK-NODS %s
+// RUN:   | FileCheck --check-prefix=CHECK-NOFS --check-prefix=CHECK-DS-DEFAULT %s
 
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1   \
 // RUN: -target i386-unknown-linux \
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -991,6 +991,13 @@
   Args.hasArg(OPT_ffunction_sections) ||
   (Opts.BBSections != "none" && Opts.BBSections != "labels");
 
+  if (Args.getLastArg(OPT_fdata_sections) ||
+  Args.getLastArg(OPT_fno_data_sections)) {
+Opts.HasExplicitDataSections = true;
+Opts.DataSections =
+Args.hasFlag(OPT_fdata_sections, OPT_fno_data_sections, false);
+  }
+
   Opts.DataSections = Args.hasArg(OPT_fdata_sections);
   Opts.StackSizeSection = Args.hasArg(OPT_fstack_size_section);
   Opts.UniqueSectionNames = !Args.hasArg(OPT_fno_unique_section_names);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4906,8 +4906,13 @@
 }
   }
 
-  if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
-   UseSeparateSections)) {
+  if (Arg *A = Args.getLastArg(options::OPT_fdata_sections,
+   options::OPT_fno_data_sections)) {
+if (A->getOption().matches(options::OPT_fdata_sections))
+  CmdArgs.push_back("-fdata-sections");
+else
+  CmdArgs.push_back("-fno-data-sections");
+  } else if (UseSeparateSections) {
 CmdArgs.push_back("-fdata-sections");
   }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -517,6 +517,7 @@
   Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
   Options.FunctionSections = CodeGenOpts.FunctionSections;
   Options.DataSections =