<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - GlobalOpt removes SectionAttr unexpecedly"
   href="http://llvm.org/bugs/show_bug.cgi?id=19474">bug 19474</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>david.majnemer@gmail.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - GlobalOpt removes SectionAttr unexpecedly"
   href="http://llvm.org/bugs/show_bug.cgi?id=19474#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - GlobalOpt removes SectionAttr unexpecedly"
   href="http://llvm.org/bugs/show_bug.cgi?id=19474">bug 19474</a>
              from <span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span></b>
        <pre>I discussed this with David Majnemer, and we think LLVM is working as intended.
You need to mark the data as "used" somehow to prevent its deletion or
localization.

The first test case is making the static global a local variable of main,
because LLVM knows that main is the program entry point, and it cannot be
invoked twice.

The second test case is just LLVM deleting an unreferenced global.

In both cases, adding __attribute__((used)) will resolve the issue.

GCC also has the same behavior. Consider this code:

void f() {
  static int a_var __attribute__((section("MySection"))) = 10;
}

GCC with -O2 will not emit the a_var global.</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>