Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fail on nonempty sections in a GNU ld linker script?

I have this in my GNU ld linker script:

  .ctors : ALIGN(4) SUBALIGN(4) {
    *(.ctors)
    ASSERT(0, "Constructors (.ctors) are not supported.");
  }

In earlier versions of GNU ld (such as 2.24), this triggered the assertion only if the section .ctors was nonempty. In newer version, it always triggers the assertion. How do I trigger it only if .ctors is nonempty?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

in this example , the __ctors_start variable should be defined prior to being used in the section’s definition.

.ctors : ALIGN(4) SUBALIGN(4) {
    *(.ctors)
    __ctors_end = .;
    __ctors_size = __ctors_end - __ctors_start;
    __ctors_start = .;
    ASSERT(__ctors_size == 0, "Constructors (.ctors) are not supported.");
}

this is an updated version of the linker script that properly defines __ctors_start before utilizing it in the section definition

.ctors : ALIGN(4) SUBALIGN(4) {
    __ctors_start = .;
    *(.ctors)
    __ctors_end = .;
    __ctors_size = __ctors_end - __ctors_start;
    ASSERT(__ctors_size == 0, "Constructors (.ctors) are not supported.");
}

good luck !

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading