Есть ли gfortran, эквивалентный __attribute g cc __ ((section ("name")))? - PullRequest
2 голосов
/ 07 февраля 2020

Я использую пакет nestedvm, который включает в себя исправленный компилятор Gnu g cc. Для этого пакета вызываемые пользовательские методы / функции должны быть помечены __attribute__((section(".text"))), как показано в примере C ниже.

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);
}

Я не знаю о внутренней работе пропатченного компилятора, но без этой аннотации пользовательская функция не видна внешним абонентам.

Как при использовании gfortran как можно Я выполнил sh эту аннотацию для подпрограмм и функций Фортрана? Можно ли это сделать с помощью файла сценария компоновщика? Я мог бы написать оболочку C для функций Фортрана, но хотел бы избежать этого, если это возможно.

** ОБНОВЛЕНИЕ 1 ** Использование nm для исследования файла .o проливает некоторый свет на проблему .. .a C метод без атрибута выглядит как функция suckram (которая не вызывается в nestedvm), в то время как функция echo имеет атрибут и может вызываться в nestedvm:

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

Подпрограмма test1 в моем Объект Fortran выглядит как метод suckram без атрибута:

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

Согласно некоторой документации nestedvm, которую я нашел, чтобы пользовательская функция могла вызываться в nestedvm, она должна заканчиваться на .text section.

** ОБНОВЛЕНИЕ 2 ** Командная строка ссылки находится ниже. Это слишком долго, чтобы оставить комментарий. Я удалил некоторые из многих файлов .o (…)

mips-unknown-elf-gfortran -O3 -mmemcpy -ffunction-sections -fdata-sections -falign-functions=512 -fno-rename-registers -fno-schedule-insns -fno-delayed-branch -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec -I. -Wall -Wno-unused -o build/refprop/Refprop.mips build/refprop/NVM.o (...) build/refprop/TRNS_VIS.o build/refprop/MAIN.o -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec --static -Wl,--gc-sections -Wl,-Map=output1.map -Wl,--cref -lc -Wl,-Map=output.map -Wl,--cref

Кроме того, хотя я называю код библиотекой, nestedvm требует, чтобы в библиотеке была подпрограмма MAIN для инициализация. Если я сделаю несколько фиктивных вызовов библиотечных функций в подпрограмме MAIN, те функции, которые вызываются в MAIN, перемещаются в раздел .text и становятся вызываемыми.

** UPDATE 3 ** Подробный вывод из make , Я удалил некоторые из множества файлов .o (…)

mips-unknown-elf-gfortran -O3 -mmemcpy -ffunction-sections -fdata-sections -falign-functions=512 -fno-rename-registers -fno-schedule-insns -fno-delayed-branch -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec -I. -Wall -Wno-unused -o build/refprop/Refprop.mips build/refprop/NVM.o (…) build/refprop/TRNS_VIS.o build/refprop/MAIN.o -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec --static -Wl,--gc-sections -Wl,-Map=output1.map -Wl,--cref -lc -Wl,-Map=output.map -Wl,--cref -v

Driving: mips-unknown-elf-gfortran -O3 -mmemcpy -ffunction-sections -fdata-sections -falign-functions=512 -fno-rename-registers -fno-schedule-insns -fno-delayed-branch -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec -I. -Wall -Wno-unused -o build/refprop/Refprop.mips build/refprop/NVM.o (…) build/refprop/TRNS_VIS.o build/refprop/MAIN.o -march=mips1 -specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec --static -Wl,--gc-sections -Wl,-Map=output1.map -Wl,--cref -lc -Wl,-Map=output.map -Wl,--cref -v -l gfortran -l m

Using built-in specs. Reading specs from /home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec Reading specs from /home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec COLLECT_GCC=mips-unknown-elf-gfortran COLLECT_LTO_WRAPPER=/home/jhuber/Documents/source/nestedvm/upstream/install/libexec/gcc/mips-unknown-elf/4.8.5/lto-wrapper Target: mips-unknown-elf Configured with: ../gcc-4.8.5/configure --prefix=/home/jhuber/Documents/source/nestedvm/upstream/install --target=mips-unknown-elf --disable-threads --disable-libssp --with-gnu-ld --with-gnu-as --with-newlib=yes --enable-sjlj-exceptions --enable-languages=c : (reconfigured) ../gcc-4.8.5/configure --prefix=/home/jhuber/Documents/source/nestedvm/upstream/install --target=mips-unknown-elf --disable-threads --disable-libssp --with-gnu-ld --with-gnu-as --with-newlib=yes --enable-sjlj-exceptions --enable-languages=c --enable-languages=c,c++,fortran Thread model: single gcc version 4.8.5 (GCC) Reading specs from /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/../../../../mips-unknown-elf/lib/libgfortran.spec rename spec lib to liborig COLLECT_GCC_OPTIONS='-O3' '-mmemcpy' '-ffunction-sections' '-fdata-sections' '-falign-functions=512' '-fno-rename-registers' '-fno-schedule-insns' '-fno-delayed-branch' '-march=mips1' '-specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec' '-I' '.' '-Wall' '-Wno-unused' '-o' 'build/refprop/Refprop.mips' '-march=mips1' '-specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec' '-static' '-v' COMPILER_PATH=/home/jhuber/Documents/source/nestedvm/upstream/install/libexec/gcc/mips-unknown-elf/4.8.5/:/home/jhuber/Documents/source/nestedvm/upstream/install/libexec/gcc/mips-unknown-elf/4.8.5/:/home/jhuber/Documents/source/nestedvm/upstream/install/libexec/gcc/mips-unknown-elf/:/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/:/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/:/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/../../../../mips-unknown-elf/bin/ LIBRARY_PATH=/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/:/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/../../../../mips-unknown-elf/lib/ COLLECT_GCC_OPTIONS='-O3' '-mmemcpy' '-ffunction-sections' '-fdata-sections' '-falign-functions=512' '-fno-rename-registers' '-fno-schedule-insns' '-fno-delayed-branch' '-march=mips1' '-specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec' '-I' '.' '-Wall' '-Wno-unused' '-o' 'build/refprop/Refprop.mips' '-march=mips1' '-specs=/home/jhuber/Documents/source/nestedvm/upstream/install/mips-unknown-elf/lib/crt0-override.spec' '-static' '-v' /home/jhuber/Documents/source/nestedvm/upstream/install/libexec/gcc/mips-unknown-elf/4.8.5/collect2 -EB -o build/refprop/Refprop.mips /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/crti.o /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/crtbegin.o /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/../../../../mips-unknown-elf/lib/crt0.o -L/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5 -L/home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/../../../../mips-unknown-elf/lib build/refprop/NVM.o (…) build/refprop/TRNS_VIS.o build/refprop/MAIN.o --gc-sections -Map=output1.map --cref -lc -Map=output.map --cref -lgfortran -lm -lgcc -lm -lgcc -lgcc /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/crtend.o /home/jhuber/Documents/source/nestedvm/upstream/install/lib/gcc/mips-unknown-elf/4.8.5/crtn.o

1 Ответ

0 голосов
/ 08 февраля 2020

Я провел несколько локальных тестов, и -ffunction-sections помещает каждую функцию fortran в свой собственный раздел, как и ожидалось. Сравните:

$ gfortran -c -O3 -o hello.o hello.f90
$ objdump -h hello.o 

hello.o:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         000000aa  0000000000000000  0000000000000000  00000040  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000  000000ea  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  0000000000000000  0000000000000000  000000ea  2**0
                  ALLOC
  3 .rodata.str1.1 0000000a  0000000000000000  0000000000000000  000000ea  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .text.startup 00000026  0000000000000000  0000000000000000  00000100  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  5 .rodata       0000001c  0000000000000000  0000000000000000  00000130  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .comment      00000026  0000000000000000  0000000000000000  0000014c  2**0
                  CONTENTS, READONLY
  7 .note.GNU-stack 00000000  0000000000000000  0000000000000000  00000172  2**0
                  CONTENTS, READONLY
  8 .eh_frame     00000068  0000000000000000  0000000000000000  00000178  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

с:

$ gfortran -ffunction-sections -c -O3 -o hello.o hello.f90
$ objdump -h hello.o 

hello.o:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00000000  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  0000000000000000  0000000000000000  00000040  2**0
                  ALLOC
  3 .rodata.str1.1 0000000a  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .text.MAIN__  00000097  0000000000000000  0000000000000000  00000050  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  5 .text.foo_    0000000a  0000000000000000  0000000000000000  000000f0  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  6 .text.startup.main 00000026  0000000000000000  0000000000000000  00000100  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  7 .rodata       0000001c  0000000000000000  0000000000000000  00000130  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  8 .comment      00000026  0000000000000000  0000000000000000  0000014c  2**0
                  CONTENTS, READONLY
  9 .note.GNU-stack 00000000  0000000000000000  0000000000000000  00000172  2**0
                  CONTENTS, READONLY
 10 .eh_frame     00000068  0000000000000000  0000000000000000  00000178  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA

Встроенный скрипт компоновщика на моем локальном компьютере по умолчанию объединяет их в .text. Похоже, что вы связываете не с. Вы должны быть в состоянии изменить этот скрипт, чтобы делать то, что вы пытаетесь. Это немного сложнее, чем расширения атрибутов, так как вам придется вести список в отдельном файле, но вы сможете найти то, что вам нравится. Я могу привести пример здесь, если вы дадите дополнительную информацию об этом в своем вопросе.

...