- Remove custom handling of jumptables by the elf writter (this was
a dirty hack and isn't need anymore since the last x86 code emitter patch)
- Add a target-dependent modifier to addend calculation
- Use R_X86_64_32S relocation for X86::reloc_absolute_word_sext
- Use getELFSectionFlags whenever possible
- fix getTextSection to use TLOF and emit the right text section 
- Handle global emission for static ctors, dtors and Type::PointerTyID
- Some minor fixes



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78176 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/ELFCodeEmitter.cpp b/lib/CodeGen/ELFCodeEmitter.cpp
index d363adb..61a9d5a 100644
--- a/lib/CodeGen/ELFCodeEmitter.cpp
+++ b/lib/CodeGen/ELFCodeEmitter.cpp
@@ -40,7 +40,7 @@
         << MF.getFunction()->getName() << "\n");
 
   // Get the ELF Section that this function belongs in.
-  ES = &EW.getTextSection();
+  ES = &EW.getTextSection(MF.getFunction());
 
   // Set the desired binary object to be used by the code emitters
   setBinaryObject(ES);
@@ -52,7 +52,7 @@
   ES->emitAlignment(Align);
 
   // Update the section alignment if needed.
-  if (ES->Align < Align) ES->Align = Align;
+  ES->Align = std::max(ES->Align, Align);
 
   // Record the function start offset
   FnStartOff = ES->getCurrentPCOffset();
@@ -73,7 +73,7 @@
                                 EW.getGlobalELFVisibility(F));
   FnSym->SectionIdx = ES->SectionIdx;
   FnSym->Size = ES->getCurrentPCOffset()-FnStartOff;
-  EW.addGlobalSymbol(F);
+  EW.addGlobalSymbol(F, true);
 
   // Offset from start of Section
   FnSym->Value = FnStartOff;
@@ -83,22 +83,21 @@
 
   // Patch up Jump Table Section relocations to use the real MBBs offsets
   // now that the MBB label offsets inside the function are known.
-  ELFSection &JTSection = EW.getJumpTableSection();
-  for (std::vector<MachineRelocation>::iterator MRI = JTRelocations.begin(),
-       MRE = JTRelocations.end(); MRI != MRE; ++MRI) {
-    MachineRelocation &MR = *MRI;
-    unsigned MBBOffset = getMachineBasicBlockAddress(MR.getBasicBlock());
-    MR.setResultPointer((void*)MBBOffset);
-    MR.setConstantVal(ES->SectionIdx);
-    JTSection.addRelocation(MR);
+  if (!MF.getJumpTableInfo()->isEmpty()) {
+    ELFSection &JTSection = EW.getJumpTableSection();
+    for (std::vector<MachineRelocation>::iterator MRI = JTRelocations.begin(),
+         MRE = JTRelocations.end(); MRI != MRE; ++MRI) {
+      MachineRelocation &MR = *MRI;
+      unsigned MBBOffset = getMachineBasicBlockAddress(MR.getBasicBlock());
+      MR.setResultPointer((void*)MBBOffset);
+      MR.setConstantVal(ES->SectionIdx);
+      JTSection.addRelocation(MR);
+    }
   }
 
-  // Relocations
-  // -----------
   // If we have emitted any relocations to function-specific objects such as
   // basic blocks, constant pools entries, or jump tables, record their
-  // addresses now so that we can rewrite them with the correct addresses
-  // later.
+  // addresses now so that we can rewrite them with the correct addresses later
   for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
     MachineRelocation &MR = Relocations[i];
     intptr_t Addr;
@@ -115,6 +114,7 @@
       MR.setConstantVal(CPSections[MR.getConstantPoolIndex()]);
       MR.setResultPointer((void*)Addr);
     } else if (MR.isJumpTableIndex()) {
+      ELFSection &JTSection = EW.getJumpTableSection();
       Addr = getJumpTableEntryAddress(MR.getJumpTableIndex());
       MR.setConstantVal(JTSection.SectionIdx);
       MR.setResultPointer((void*)Addr);