[LLVMdev] Create "appending" section that can be partially dead stripped

Reid Kleckner rnk at google.com
Tue Aug 5 10:31:34 PDT 2014


On Tue, Aug 5, 2014 at 7:34 AM, Jonas Maebe <jonas.maebe at elis.ugent.be>
wrote:
>
> 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.
>

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.

A good starting point for this kind of stuff is to look at what Clang does
on C code like this:

$ cat t.cpp
extern "C" int printf(const char *, ...);
extern int __start_my_section[];
extern int __stop_my_section[];
int __attribute__((section("my_section"))) a = 1;
int __attribute__((section("my_section"))) b = 2;
int main() {
  for (int *i = &__start_my_section[0], *e = &__stop_my_section[0]; i != e;
       ++i) {
    printf("%d ", *i);
  }
  printf("\n");
}

$ clang -cc1 t.cpp -emit-llvm -o -
... // omitted

Speaking of which, I believe both ld.bfd and ld.gold define
__start_my_section for you, which should make your life easier.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140805/c3514913/attachment.html>


More information about the llvm-dev mailing list