gustavonihei commented on pull request #3836:
URL: https://github.com/apache/incubator-nuttx/pull/3836#issuecomment-857100867


   > **I still haven't figured out exactly why**, but it seems for these cases 
where the Linker is required to perform the section placement from specific 
input files we need to forward the linker script file to the linker:
   > 
   > ```diff
   > diff --git a/boards/arm/rp2040/raspberrypi-pico/scripts/Make.defs 
b/boards/arm/rp2040/raspberrypi-pico/scripts/Make.defs
   > index 2f810badf8..5f58732ab4 100644
   > --- a/boards/arm/rp2040/raspberrypi-pico/scripts/Make.defs
   > +++ b/boards/arm/rp2040/raspberrypi-pico/scripts/Make.defs
   > @@ -30,9 +30,9 @@ else
   >  endif
   >  
   >  ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
   > -  ARCHSCRIPT = -T "${shell cygpath -w 
$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
   > +  ARCHSCRIPT = -Wl,-T,"${shell cygpath -w 
$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
   >  else
   > -  ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
   > +  ARCHSCRIPT = -Wl,-T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
   >  endif
   >  
   >  ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
   > ```
   > 
   > After this change and reverting the modification to the linker scripts the 
generated output was correct.
   
   I think now I got to figure it out (maybe not completely).
   
   Functionality-wise there is no difference between passing the linker script 
via **-T** and **-Wl,-T**, but it will impact on the order of arguments that 
will be provided to the **collect2** internal GCC command, which is the one 
that invokes the actual linker.
   
   **-T** will be interpreted by the GCC driver and will be added to the 
`COLLECT_GCC_OPTIONS`, which is an environment variable used by GCC to store 
arguments that will be passed to its subprocesses.
   **-Wl,-T**, on the other hand, explicitly tells GCC that the **-T** flag 
shall be forwarded to the linker, so it won't be added to `COLLECT_GCC_OPTIONS` 
environment variable.
   
   The difference in the results lies in how GCC parses the flags from 
`COLLECT_GCC_OPTIONS` and add them no the `collect2` command line.
   The `multiple definition` error occurs because **-T** flag is processed by 
**collect2** after the `--start-group -lsched -ldrivers -lboards -lc -lmm 
-larch -lapps -lfs -lbinfmt -lboard -lgcc -lm --end-group` libraries.
   
   See the output from the verbose builds:
   
   ### Using -T
   ```shell
   $ arm-none-eabi-gcc --verbose -Wl,--entry=__start -nostartfiles 
-nodefaultlibs -g 
-T/home/nihei/Projects/NuttX/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-sram.ld
  -L"/home/nihei/Projects/NuttX/nuttx/staging" 
-L"/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board" -L 
"/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp"
 -L 
"/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp"
 -o "/home/nihei/Projects/NuttX/nuttx/nuttx" -Wl,--start-group -lsched 
-ldrivers -lboards -lc -lmm -larch -lapps -lfs -lbinfmt -lboard -lgcc -lm 
-Wl,--end-group
   Using built-in specs.
   COLLECT_GCC=arm-none-eabi-gcc
   
COLLECT_LTO_WRAPPER=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper
   Target: arm-none-eabi
   Configured with: 
/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/src/gcc/configure
 --target=arm-none-eabi 
--prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native
 
--libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/lib
 
--infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/info
 
--mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/man
 
--htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/html
 
--pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/pdf
 --enable-languages=c,c++ --enable-plu
 gins --disable-decimal-float --disable-libffi --disable-libgomp 
--disable-libmudflap --disable-libquadmath --disable-libssp 
--disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads 
--disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes 
--with-python-dir=share/gcc-arm-none-eabi 
--with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/arm-none-eabi
 --build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/u
 sr 
--with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' 
--with-pkgversion='GNU Arm Embedded Toolchain 10-2020-q4-major' 
--with-multilib-list=rmprofile,aprofile
   Thread model: single
   Supported LTO compression algorithms: zlib
   gcc version 10.2.1 20201103 (release) (GNU Arm Embedded Toolchain 
10-2020-q4-major) 
   
COMPILER_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/
   
LIBRARY_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi/lib/
   COLLECT_GCC_OPTIONS='-v' '-nostartfiles' '-nodefaultlibs' '-g' '-T' 
'/home/nihei/Projects/NuttX/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-sram.ld'
 '-L/home/nihei/Projects/NuttX/nuttx/staging' 
'-L/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board' 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp'
 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp'
 '-o' '/home/nihei/Projects/NuttX/nuttx/nuttx' '-mcpu=arm7tdmi' 
'-mfloat-abi=soft' '-marm' '-march=armv4t'
   
*****************************************************************************************************************************
   
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/collect2
 -plugin 
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/liblto_plugin.so
 
-plugin-opt=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper
 -plugin-opt=-fresolution=/tmp/ccDnGwsd.res 
--sysroot=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi -X -o 
/home/nihei/Projects/NuttX/nuttx/nuttx 
-L/home/nihei/Projects/NuttX/nuttx/staging 
-L/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp
 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp
 -L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-e
 abi/lib -L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi/lib 
--entry=__start --start-group -lsched -ldrivers -lboards -lc -lmm -larch -lapps 
-lfs -lbinfmt -lboard -lgcc -lm --end-group -T 
/home/nihei/Projects/NuttX/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-sram.ld
   
*****************************************************************************************************************************
   
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld:
 rp2040_start.o: in function `__start':
   /home/nihei/Projects/NuttX/nuttx/arch/arm/src/chip/rp2040_start.c:52: 
multiple definition of `__start'; 
/home/nihei/Projects/NuttX/nuttx/staging/libarch.a(rp2040_start.o):/home/nihei/Projects/NuttX/nuttx/arch/arm/src/chip/rp2040_start.c:52:
 first defined here
   
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld:
 
rp2040_start.o:/home/nihei/Projects/NuttX/nuttx/arch/arm/src/chip/rp2040_start.c:52:
 multiple definition of `g_idle_topstack'; 
/home/nihei/Projects/NuttX/nuttx/staging/libarch.a(rp2040_start.o):/home/nihei/Projects/NuttX/nuttx/arch/arm/src/chip/rp2040_start.c:52:
 first defined here
   collect2: error: ld returned 1 exit status
   ```
   
   ### Using -Wl,-T
   ```shell
   $ arm-none-eabi-gcc --verbose -Wl,--entry=__start -nostartfiles 
-nodefaultlibs -g 
-Wl,-T/home/nihei/Projects/NuttX/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-sram.ld
  -L"/home/nihei/Projects/NuttX/nuttx/staging" 
-L"/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board" -L 
"/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp"
 -L 
"/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp"
 -o "/home/nihei/Projects/NuttX/nuttx/nuttx" -Wl,--start-group -lsched 
-ldrivers -lboards -lc -lmm -larch -lapps -lfs -lbinfmt -lboard -lgcc -lm 
-Wl,--end-group
   Using built-in specs.
   COLLECT_GCC=arm-none-eabi-gcc
   
COLLECT_LTO_WRAPPER=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper
   Target: arm-none-eabi
   Configured with: 
/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/src/gcc/configure
 --target=arm-none-eabi 
--prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native
 
--libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/lib
 
--infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/info
 
--mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/man
 
--htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/html
 
--pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/pdf
 --enable-languages=c,c++ --enable-plu
 gins --disable-decimal-float --disable-libffi --disable-libgomp 
--disable-libmudflap --disable-libquadmath --disable-libssp 
--disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads 
--disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes 
--with-python-dir=share/gcc-arm-none-eabi 
--with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/arm-none-eabi
 --build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 
--with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/u
 sr 
--with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr
 --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' 
--with-pkgversion='GNU Arm Embedded Toolchain 10-2020-q4-major' 
--with-multilib-list=rmprofile,aprofile
   Thread model: single
   Supported LTO compression algorithms: zlib
   gcc version 10.2.1 20201103 (release) (GNU Arm Embedded Toolchain 
10-2020-q4-major) 
   
COMPILER_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/
   
LIBRARY_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/:/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi/lib/
   COLLECT_GCC_OPTIONS='-v' '-nostartfiles' '-nodefaultlibs' '-g' 
'-L/home/nihei/Projects/NuttX/nuttx/staging' 
'-L/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board' 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp'
 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp'
 '-o' '/home/nihei/Projects/NuttX/nuttx/nuttx' '-mcpu=arm7tdmi' 
'-mfloat-abi=soft' '-marm' '-march=armv4t'
   
*****************************************************************************************************************************
   
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/collect2
 -plugin 
/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/liblto_plugin.so
 
-plugin-opt=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper
 -plugin-opt=-fresolution=/tmp/ccjfgjvm.res 
--sysroot=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi -X -o 
/home/nihei/Projects/NuttX/nuttx/nuttx 
-L/home/nihei/Projects/NuttX/nuttx/staging 
-L/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp
 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp
 -L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc 
-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-e
 abi/lib -L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../arm-none-eabi/lib 
--entry=__start 
-T/home/nihei/Projects/NuttX/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-sram.ld
 --start-group -lsched -ldrivers -lboards -lc -lmm -larch -lapps -lfs -lbinfmt 
-lboard -lgcc -lm --end-group
   
*****************************************************************************************************************************
   COLLECT_GCC_OPTIONS='-v' '-nostartfiles' '-nodefaultlibs' '-g' 
'-L/home/nihei/Projects/NuttX/nuttx/staging' 
'-L/home/nihei/Projects/NuttX/nuttx/arch/arm/src/board' 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/thumb/v6-m/nofp'
 
'-L/opt/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp'
 '-o' '/home/nihei/Projects/NuttX/nuttx/nuttx' '-mcpu=arm7tdmi' 
'-mfloat-abi=soft' '-marm' '-march=armv4t'
   ``` 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to