0

I have a program that places some structs in a named section using __attribute__ ((".sdh_ble_observers")) and extern mytype * ___start_sdh_ble_observers.

I'm using the following linker script

SECTIONS
{
  .sdh_ble_observers :
  {
    PROVIDE(___start_sdh_ble_observers = .);
    KEEP(*(SORT(.sdh_ble_observers*)))
    PROVIDE(___stop_sdh_ble_observers = .);
  }
}
INSERT AFTER .data;

When I use g++ to link the application using the -T flag for the linker script, the executable becomes un-executable cannot execute binary file: Exec format error.

When I remove the extern declarations in the code and don't use the -T flag in g++ the executable runs fine.

What can be the cause of this? The platform is cygwin.

Andy
  • 109
  • 1
  • 10
  • "-Doctor, it hurts when I do that, what's your advice? - Don't do that." What are you trying to achieve? – SergeyA Jun 05 '18 at 17:54
  • Is this for ARM? – Michael Petch Jun 05 '18 at 18:06
  • @MichaelPetch no, the architecture is x86 with cygwin under Windows 10. – Andy Jun 05 '18 at 19:06
  • @SergeyA I'm trying to run some code that was written for ARM on my local platform. It's working smoothly for the most part. But there are these macros in the code that define observers for callbacks from a module that I have to mock on my local platform. So the idea is to get this to run somehow without changing the original code. On ARM it's achieved using a named section and a linker script - shouldn't the same be possible under x86? – Andy Jun 05 '18 at 19:06

1 Answers1

0

I just found the answer to the problem.

Adding an align statement to the section .sdh_ble_observers : ALIGN(0x1000) did the trick.

Andy
  • 109
  • 1
  • 10