title: How can the --add-section switch of OBJCOPY be used?
body: <p>There are really two questions that revolve around the use of --add-section.  The simple one is in the title.  Based on my reading, I haven't been able to figure out how one could execute --add-section.</p>
  
  <p>To use add-section, I have to pass a section name.  If I use an existing section name the program responds with "can't add section '.data': File in wrong format."  Perhaps I just need to pass another parameter.  If I use a new section name, which I would prefer to do, I'm warned that "allocated section '.blob' not in segment."</p>
  
  <p>Now, I have gotten my feature to work as I need it to aside from the "not in segment" warning.  I'd like to figure out if there is a legitimate way to put this blob into the executable.  I would link it in, but that isn't so easy because the data I'm adding is generated from the contents of the executable itself.</p>
  
  <p>The second question is really what I care about.  Is there a way to do the following given that the blob cannot be computed until after the link is complete.</p>
  
  <ol>
  <li>Link ELF file</li>
  <li>Generate blob from ELF file and other data</li>
  <li><p>Add blob to ELF file so that it is loaded at run-time to the correct location in memory</p>
  
  <p><code>objcopy --add-section .blob=blob.o \
      --set-section-flags .blob=alloc,contents,load,readonly \
      --change-section-address .blob=ADDRESS \
      program.elf  program.blobbed.elf</code></p></li>
  </ol>
  
  <p>I'd be happy to add a section and/or segment to the ELF file as part of the link and insert this blob there.  I'm not sure how to do that.</p>
  
  <p>It has occurred to me that I could accomplish this feat with a second link, but objcopy would be cleaner.</p>
  
  <ol>
  <li>Link ELF file</li>
  <li>Generate blob from ELF file and other data</li>
  <li>Re-link ELF file including new blob.o</li>
  </ol>
  
  <p><strong>UPDATE:</strong> This last strategy may be workable as long as the relink doesn't change something in the portion of the program that was produced by the first link.  It doesn't on first attempts, but it may be possible to work around it.  Hence, the desire to use --add-section to add in this blob instead of going through a second link.</p>