How to define C-like register macro in C++

Viewed 147

I always fancy MODULE_INIT macro in linux kernel source code. So I try to make similar macro in C++.

AFAIK, MODULE_INIT will put a function into a memory section.

So I try,

void __attribute__((section("mysec")) func();

This works fine when compile with -o. But when I link it with gold the section disappears in final execution file.

Here is the linker script

SECTIONS {
   mysec: {
    __start_mysec = .;
    (*mysec)
    __end_mysec = . ;
  }
}

INSERT AFTER/BEFORE not work with gold, so I ignore it.

So, How do I replicate MODULE_INIT macro with c++?

I'm using arm-oe-linux-gnueabi-g++ for this. So #pragma section does not exist.

0 Answers
Related