[PATCH] D18691: [ELF] - Split Writer::assignAddresses(): extract code for dummies to fixDummiesSections()

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 04:41:26 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

This change works like NFC, 

it starts to do next for relocatable output:
```
  size_t PhdrSize = sizeof(Elf_Phdr) * Phdrs.size();
  Out<ELFT>::ProgramHeaders->setSize(PhdrSize);
```
But at that place Phdrs size is zero and anyways relocatable 
output does not include the program headers.

Not sure it is worth the review, posting it just in case.
In combine with r265130 and r265131 this will make almost no
duplicated code in not yet published assignAddressLinkerscript()

http://reviews.llvm.org/D18691

Files:
  ELF/Writer.cpp

Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -72,6 +72,7 @@
   void assignAddresses();
   void assignAddressesRelocatable();
   void assignPhdrs();
+  void fixDummiesSections();
   void fixSectionAlignments();
   void fixAbsoluteSymbols();
   bool openFile();
@@ -215,8 +216,11 @@
   addReservedSymbols();
   if (!createSections())
     return;
-  if (!Config->Relocatable) {
+  if (!Config->Relocatable)
     createPhdrs();
+  fixDummiesSections();
+
+  if (!Config->Relocatable) {
     fixSectionAlignments();
     assignAddresses();
   } else {
@@ -1380,11 +1384,16 @@
   return FileOff;
 }
 
+template <class ELFT> void Writer<ELFT>::fixDummiesSections() {
+  Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
+  size_t PhdrSize = sizeof(Elf_Phdr) * Phdrs.size();
+  Out<ELFT>::ProgramHeaders->setSize(PhdrSize);
+}
+
 // Used for relocatable output (-r). In this case we create only ELF file
 // header, do not create program headers. Also assign of section addresses
 // is very straightforward: we just put all sections sequentually to the file.
 template <class ELFT> void Writer<ELFT>::assignAddressesRelocatable() {
-  Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
   uintX_t FileOff = 0;
   for (OutputSectionBase<ELFT> *Sec : OutputSections)
     FileOff = fixFileOff(FileOff, Sec->getAlign(), Sec);
@@ -1395,10 +1404,6 @@
 // Visits all headers in PhdrTable and assigns the adresses to
 // the output sections. Also creates common and special headers.
 template <class ELFT> void Writer<ELFT>::assignAddresses() {
-  Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
-  size_t PhdrSize = sizeof(Elf_Phdr) * Phdrs.size();
-  Out<ELFT>::ProgramHeaders->setSize(PhdrSize);
-
   uintX_t ThreadBssOffset = 0;
   uintX_t VA = Target->getVAStart();
   uintX_t FileOff = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18691.52350.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160401/78cbc171/attachment.bin>


More information about the llvm-commits mailing list