<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Cannot dump all stack sizes in fully linked output if some entries come from different sections"
   href="https://bugs.llvm.org/show_bug.cgi?id=45228">45228</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cannot dump all stack sizes in fully linked output if some entries come from different sections
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-readobj
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jh7370.2008@my.bristol.ac.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jh7370.2008@my.bristol.ac.uk, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Imagine the following piece of code:

__attribute__((section(".wibble")))
int baz () {
    int a[42];
    return sizeof(a);
}

int _start(){
    int x = 1;
    return baz() + x; 
}

When compiled, this will produce sections ".wibble" and ".text", each with
their own .stack_sizes section. When linked, .wibble and .text remain as
separate sections, but the two .stack_sizes sections are concatenated into one.
The .stack_sizes section has a sh_link field pointing to the section containing
the functions it refers to. This works fine in the ET_REL object, but in the
final link, the linker has to pick one section to use. llvm-readobj uses the
sh_link value to determine which symbols are candidates for each individual
stack size entry: if they are in the "wrong" section, they don't get
considered. This has the result of not finding symbols for some sections. For
the above piece of code, I get the following output from llvm-readelf:

C:\Work\PPRBUG-25593> C:\llvm\build\Debug\bin\llvm-readelf.exe --stack-sizes
repro.elf

Stack Sizes:
         Size     Function
           24     _start
C:\llvm\build\Debug\bin\llvm-readelf.exe: warning: 'repro.elf': could not
identify function symbol for stack size entry
           56     ?

I think we need to do two things:
1) Set the sh_link to 0 in the linked output. This will require an LLD change.
2) Change llvm-readelf to not do the section check in the event that sh_link is
0. There shouldn't be any ambiguity between symbols in this case, so it is not
a degradation in correctness, although I suppose technically there's nothing
stopping symbols being in non-alloc sections, in which case we might want to
special case that (although they won't be STT_FUNC, so there's probably no
need).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>