On 10/18/24 14:17, Andrew Pinski wrote:
On Thu, Oct 17, 2024 at 7:52 PM ChenQi <qi.c...@windriver.com> wrote:
Hi Fortran community,

I recently got a buildpath issue when building libgfortran. I'm sending
out email to this mailing list first, but if you think it's a bug
instead of some expected behavior, please let me know and I'll file a bug.

Here's the issue: the generated binary has buildpath in the
DW_AT_producer section. Below are some output from 'readelf --debug-dump
libgfortran.so.5.0.0'.

"""

<0><1a37d3>: Abbrev Number: 4 (DW_TAG_compile_unit)
          <1a37d4>   DW_AT_producer    : (indirect string, offset:
0xd653): GNU Fortran2008 14.2.0 -m64 -march=core2 -mtune=core2 -msse3
-mfpmath=sse -mshstk -g -O2 -O2 -fstack-protector-strong -fimplicit-none
-fno-repack-arrays -fno-underscoring -fcf-protection=full
-fallow-leading-underscore -fbuilding-libgfortran -fPIC
-fintrinsic-modules-path
/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../lib/x86_64-poky-linux/gcc/x86_64-poky-linux/14.2.0/finclude
-fpre-include=../../../../recipe-sysroot/usr/include/finclude/math-vector-fortran.h

"""

The problem is that this '-fintrinsic-modules-path' is not passed by me.
Use some .o file as an example. Here's command to build out
.libs/_mod_r17.o:

"""

libtool: compile:  x86_64-poky-linux-gfortran -m64 -march=core2
-mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong -O2
-D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security
--sysroot=../../../../recipe-sysroot -fcanon-prefix-map
-fdebug-prefix-map=/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work-shared/gcc-14.2.0-r0/gcc-14.2.0=/usr/src/debug/libgfortran/14.2.0
-fdebug-prefix-map=/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/gcc-14.2.0/build.x86_64-poky-linux.x86_64-poky-linux=/usr/src/debug/libgfortran/14.2.0
-fdebug-prefix-map=/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/recipe-sysroot-native=
-DHAVE_CONFIG_H -I. -I../../../../../../../../work-shared/gcc-14.2.\
0-r0/gcc-14.2.0/libgfortran
-iquote../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/io
-I../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/../gcc
-I../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/../gcc/config
-I/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/gcc-14.2.0/build.x86_64-poky-linux.x86_64-poky-linux/x86_64-poky-linux/libgfortran/../.././gcc
-I../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/../libgcc
-I/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/gcc-14.2.0/build.x86_64-poky-linux.x86_64-poky-linux/x86_64-poky-linux/libgfortran/../libgcc
-I../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/../libbacktrace
-I/ala-lpggp72/qichen/Yocto/builds/build-poky/tmp/work/core2-64-poky-linux/libgfortran/14.2.0/gcc-14.2.0/build.x86_64-poky-linux.x86_64-poky-linux/x86_64-poky-linux/libgfortran/../libbacktrace
-I../libbacktrace -I . -Wall -Werror -fimplicit-none -fno-repack-arrays
-fno-underscoring -fcf-protection -mshstk -fallow-leading-underscore
-fbuilding-libgfortran -g -O2 -c
../../../../../../../../work-shared/gcc-14.2.0-r0/gcc-14.2.0/libgfortran/generated/_mod_r17.F90
-fPIC -o .libs/_mod_r17.o

"""

You can see that there's no '-fintrinsic-modules-path' there. This means
that this '-fintrinsic-modules-path' is added automatically by gfortran.
And the generated _mod_r17.o has buildpath encoded.

I tried to add '-fintrinsic-modules-path=/not/exist', hoping that no
extra '-fintrinsic-modules-path' option would be added, but it does not
work.

I searched the whole gcc source codes, and really cannot find any codes
that adds this option automatically.
It comes from the fortran specs:
```
#define F951_OPTIONS        "%(cc1_options) %{J*} \
                              %{!nostdinc:-fintrinsic-modules-path finclude%s}" 
\
                              TARGET_F951_OPTIONS \
                              "%{!fsyntax-only:%(invoke_as)}"
...
{"@f95",
     "f951 %i %{E:%{!cpp:%egfortran does not support -E without -cpp}}\
           %{cpp:" F951_CPP_OPTIONS ";:  " CPP_FORWARD_OPTIONS  "} \
           %{!E:" F951_OPTIONS "}", 0, 0, 0},

```

I see the producer string should only have the saved options if
dwarf_record_gcc_switches is true which is the default.
You can turn that off with -gno-record-gcc-switches so build
directories don't show up.

Thanks,
Andrew Pinski

Thanks a lot Andrew! This option works.

For anyone who is having a similar issue, here's the patch I sent to Yocto to fix this buildpath issue (libgfortran build, cross compilation environment): https://lists.openembedded.org/g/openembedded-core/message/206040

Regards,

Qi


Does someone know what's going on? Why is this
'-fintrinsic-modules-path' added automatically? Is there any way to get
rid of this buildpath?

Thanks in advance.

Regards,

Qi


Reply via email to