Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22155

Is there a gfortran equivalent to gcc's __attribute__((section("name")))?

$
0
0

I am using the nestedvm package, which includes a patched Gnu gcc compiler. For this package, callable user methods/functions have to annotated with __attribute__((section(".text"))), as shown in the C example below.

void echo(const char *string, int count)  __attribute__((section(".text")));
void echo(const char *string, int count) {
    int i;
    for(i=0;i<count;i++)
        printf("%d: %s\n",i,string);
}

I don't know about the inner workings of the patched compiler, but without this annotation, the user function is not visible to outside callers.

If using gfortran, how can I accomplish this annotation for Fortran subroutines and functions? Could this be done with a linker script file? I could write a C wrapper to the Fortran functions, but would like to avoid this if possible.

** UPDATE ** Using nm to investigate the .o file sheds some light on the issue...a C method without the attribute looks like the suckram function (which is not callable in nestedvm), while the echo function has the attribute and is callable in nestedvm:

Name                  Value   Class        Type         Size     Line  Section
suckram             |00000000|   T  |              FUNC|00000078|     |.text.suckram
echo                |00000200|   T  |              FUNC|00000074|     |.text

The test1 subroutine in my Fortran object looks like the suckram method without the attribute:

test1_              |00000000|   T  |              FUNC|00000080|     |.text.test1_

According to some nestedvm documentation I found, in order for a user function to be callable in nestedvm, it has to end up in the .text section.


Viewing all articles
Browse latest Browse all 22155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>