[yaml2obj] - Allow setting cutom Flags for implicit sections.

With this patch we get ability to set any flags we want
for implicit sections defined in YAML.

Differential revision: https://reviews.llvm.org/D63136

llvm-svn: 363367
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 6148582..cd61561 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -303,7 +303,8 @@
 
     SHeader.sh_name = DotShStrtab.getOffset(SecName);
     SHeader.sh_type = Sec->Type;
-    SHeader.sh_flags = Sec->Flags;
+    if (Sec->Flags)
+      SHeader.sh_flags = *Sec->Flags;
     SHeader.sh_addr = Sec->Address;
     SHeader.sh_addralign = Sec->AddressAlign;
 
@@ -424,8 +425,10 @@
     SHeader.sh_link = Link;
   }
 
-  if (!IsStatic)
-    SHeader.sh_flags |= ELF::SHF_ALLOC;
+  if (YAMLSec && YAMLSec->Flags)
+    SHeader.sh_flags = *YAMLSec->Flags;
+  else if (!IsStatic)
+    SHeader.sh_flags = ELF::SHF_ALLOC;
 
   // If the symbol table section is explicitly described in the YAML
   // then we should set the fields requested.
@@ -481,14 +484,16 @@
   if (YAMLSec && YAMLSec->EntSize)
     SHeader.sh_entsize = *YAMLSec->EntSize;
 
+  if (YAMLSec && YAMLSec->Flags)
+    SHeader.sh_flags = *YAMLSec->Flags;
+  else if (Name == ".dynstr")
+    SHeader.sh_flags = ELF::SHF_ALLOC;
+
   // If .dynstr section is explicitly described in the YAML
   // then we want to use its section address.
-  if (Name == ".dynstr") {
-    if (YAMLSec)
-      SHeader.sh_addr = YAMLSec->Address;
-    // We assume that .dynstr is always allocatable.
-    SHeader.sh_flags |= ELF::SHF_ALLOC;
-  }
+  // TODO: Allow this for any explicitly described section.
+  if (YAMLSec && Name == ".dynstr")
+    SHeader.sh_addr = YAMLSec->Address;
 }
 
 template <class ELFT>