<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 5, 2014 at 7:34 AM, Jonas Maebe <span dir="ltr"><<a href="mailto:jonas.maebe@elis.ugent.be" target="_blank">jonas.maebe@elis.ugent.be</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
However, I'm not sure how to add a symbol without data at the start and end of the section. Adding a [i32 x 0]-typed symbol still inserts a byte (see the @arrstart/@arrstop). I can't work with alias declarations to the first and last element, since then the first and last element will always be considered live.<br>
</blockquote><div><br></div><div>I think you want to declare those [0 x i32] globals instead of defining them by adding extern and dropping the empty brackets. Typically they are defined by the linker, and not every TU.</div>
<div><br></div><div>A good starting point for this kind of stuff is to look at what Clang does on C code like this:</div><div><br></div><div><div>$ cat t.cpp</div><div>extern "C" int printf(const char *, ...);</div>
<div>extern int __start_my_section[];</div><div>extern int __stop_my_section[];</div><div>int __attribute__((section("my_section"))) a = 1;</div><div>int __attribute__((section("my_section"))) b = 2;</div>
<div>int main() {</div><div> for (int *i = &__start_my_section[0], *e = &__stop_my_section[0]; i != e;</div><div> ++i) {</div><div> printf("%d ", *i);</div><div> }</div><div> printf("\n");</div>
<div>}</div><div><br></div><div>$ clang -cc1 t.cpp -emit-llvm -o -</div></div><div>... // omitted</div><div><br></div><div>Speaking of which, I believe both ld.bfd and ld.gold define __start_my_section for you, which should make your life easier.</div>
</div></div></div>