Build: Remove input of standard libraries in linker scripts

Removes the GROUP() command with standard libraries in the GCC linker
scripts in favour of specifying -specs=nano.specs and -specs=nosys.specs
in the toolchain file. These two specs together cause the binary to be
linked with "-lgcc -lc_nano -lnosys" which is exactly what we want. Also
specifying this in the linker script is mostly duplication, but actually
somewhat detrimental in some cases as the GROUP() command included libc,
whereas we prefer to only use libc_nano.

Also removed -nostdlib from the compile options as it is a linker option
and so had no effect there. It cannot be used as a link option with TF-M
currently since we do rely on a few things from the standard libraries.

Signed-off-by: Jamie Fox <jamie.fox@arm.com>
Change-Id: I190cad7f112df5de75417776c42af7bb9a9d9c35
diff --git a/platform/ext/common/gcc/tfm_common_bl2.ld b/platform/ext/common/gcc/tfm_common_bl2.ld
index 39b9f7e..5c1cc88 100644
--- a/platform/ext/common/gcc/tfm_common_bl2.ld
+++ b/platform/ext/common/gcc/tfm_common_bl2.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2022 Arm Limited. All rights reserved.
+; * Copyright (c) 2022-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = BL2_HEAP_SIZE;
 __msp_stack_size__ = BL2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/common/gcc/tfm_common_ns.ld b/platform/ext/common/gcc/tfm_common_ns.ld
index 5a1c7c7..8e1494a 100644
--- a/platform/ext/common/gcc/tfm_common_ns.ld
+++ b/platform/ext/common/gcc/tfm_common_ns.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = NS_HEAP_SIZE;
 __stack_size__ = NS_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/common/gcc/tfm_common_s.ld b/platform/ext/common/gcc/tfm_common_s.ld
index 3d46e104..bc7ddfc 100644
--- a/platform/ext/common/gcc/tfm_common_s.ld
+++ b/platform/ext/common/gcc/tfm_common_s.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2009-2023 Arm Limited
+; * Copyright (c) 2009-2024 Arm Limited
 ; * Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon company)
 ; * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
 ; *
@@ -65,9 +65,6 @@
 
 __msp_stack_size__ = S_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a libc_nano.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/common/gcc/tfm_isolation_l3.ld.template b/platform/ext/common/gcc/tfm_isolation_l3.ld.template
index af93c03..5cccdd1 100644
--- a/platform/ext/common/gcc/tfm_isolation_l3.ld.template
+++ b/platform/ext/common/gcc/tfm_isolation_l3.ld.template
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2009-2023 Arm Limited
+; * Copyright (c) 2009-2024 Arm Limited
 ; * Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon company)
 ; * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
 ; *
@@ -42,9 +42,6 @@
 
 __msp_stack_size__ = S_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a libc_nano.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_1.ld b/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_1.ld
index a537c4d..c550a10 100644
--- a/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_1.ld
+++ b/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_1.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2023, Arm Limited. All rights reserved.
+; * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = BL1_1_HEAP_SIZE;
 __msp_stack_size__ = BL1_1_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_2.ld b/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_2.ld
index d1d3285..2f9a5a7 100644
--- a/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_2.ld
+++ b/platform/ext/target/arm/corstone1000/Device/Source/gcc/corstone1000_bl1_2.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2023, Arm Limited. All rights reserved.
+; * Copyright (c) 2023-2024, Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = BL1_2_HEAP_SIZE;
 __msp_stack_size__ = BL1_2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/mps3/common/provisioning/provisioning_bundle.ld b/platform/ext/target/arm/mps3/common/provisioning/provisioning_bundle.ld
index a6fdb44..f5afb51 100644
--- a/platform/ext/target/arm/mps3/common/provisioning/provisioning_bundle.ld
+++ b/platform/ext/target/arm/mps3/common/provisioning/provisioning_bundle.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2021-2023 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -29,9 +29,6 @@
     VALUES (r) : ORIGIN = PROVISIONING_BUNDLE_VALUES_START, LENGTH = PROVISIONING_BUNDLE_VALUES_SIZE
 }
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(do_provisioning)
 
 SECTIONS
diff --git a/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_bl2.ld b/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_bl2.ld
index ce19c22..8865790 100644
--- a/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_bl2.ld
+++ b/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_bl2.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2009-2023 Arm Limited
+; * Copyright (c) 2009-2024 Arm Limited
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -32,9 +32,6 @@
 __heap_size__  = BL2_HEAP_SIZE;
 __msp_stack_size__ = BL2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_ns.ld b/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_ns.ld
index cd99f6d..8af0b7d 100644
--- a/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_ns.ld
+++ b/platform/ext/target/arm/musca_b1/Device/Source/gcc/musca_ns.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2009-2022 ARM Limited
+; * Copyright (c) 2009-2024 ARM Limited
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = NS_HEAP_SIZE;
 __stack_size__ = NS_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_1.ld b/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_1.ld
index 369cee4..287e721 100644
--- a/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_1.ld
+++ b/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_1.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2021-2023 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = BL1_1_HEAP_SIZE;
 __msp_stack_size__ = BL1_1_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_2.ld b/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_2.ld
index 8f26da1..8f05199 100644
--- a/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_2.ld
+++ b/platform/ext/target/arm/rss/common/device/source/gcc/rss_bl1_2.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2021-2023 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -31,9 +31,6 @@
 __heap_size__  = BL1_2_HEAP_SIZE;
 __msp_stack_size__ = BL1_2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/arm/rss/common/provisioning/bundle_common/provisioning_bundle.ld b/platform/ext/target/arm/rss/common/provisioning/bundle_common/provisioning_bundle.ld
index 985f2d3..d9974cb 100644
--- a/platform/ext/target/arm/rss/common/provisioning/bundle_common/provisioning_bundle.ld
+++ b/platform/ext/target/arm/rss/common/provisioning/bundle_common/provisioning_bundle.ld
@@ -1,5 +1,5 @@
 ;/*
-; * Copyright (c) 2021-2023 Arm Limited. All rights reserved.
+; * Copyright (c) 2021-2024 Arm Limited. All rights reserved.
 ; *
 ; * Licensed under the Apache License, Version 2.0 (the "License");
 ; * you may not use this file except in compliance with the License.
@@ -29,9 +29,6 @@
     VALUES (r) : ORIGIN = PROVISIONING_BUNDLE_VALUES_START, LENGTH = PROVISIONING_BUNDLE_VALUES_SIZE
 }
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(do_provisioning)
 
 SECTIONS
diff --git a/platform/ext/target/cypress/psoc64/Device/Source/gcc/psoc6_ns.ld b/platform/ext/target/cypress/psoc64/Device/Source/gcc/psoc6_ns.ld
index 0e59f79..24e8513 100644
--- a/platform/ext/target/cypress/psoc64/Device/Source/gcc/psoc6_ns.ld
+++ b/platform/ext/target/cypress/psoc64/Device/Source/gcc/psoc6_ns.ld
@@ -21,7 +21,6 @@
 
 OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
 SEARCH_DIR(.)
-GROUP(-lgcc -lc -lnosys)
 ENTRY(Reset_Handler)
 
 #include "region_defs.h"
@@ -65,9 +64,6 @@
     efuse             (r)     : ORIGIN = 0x90700000, LENGTH = 0x100000     /*   1 MB */
 }
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 /* Linker script to place sections and symbol values. Should be used together
  * with other linker script that defines memory regions FLASH and RAM.
  * It references following symbols, which must be defined in code:
diff --git a/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_bl2.ld b/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_bl2.ld
index 24a1730..1307529 100644
--- a/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_bl2.ld
+++ b/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_bl2.ld
@@ -31,9 +31,6 @@
 __heap_size__  = BL2_HEAP_SIZE;
 __msp_stack_size__ = BL2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_ns.ld b/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_ns.ld
index e372613..80d47fc 100644
--- a/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_ns.ld
+++ b/platform/ext/target/nuvoton/m2351/device/source/gcc/m2351_ns.ld
@@ -31,9 +31,6 @@
 __heap_size__  = NS_HEAP_SIZE;
 __stack_size__ = NS_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_bl2.ld b/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_bl2.ld
index 24a1730..1307529 100644
--- a/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_bl2.ld
+++ b/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_bl2.ld
@@ -31,9 +31,6 @@
 __heap_size__  = BL2_HEAP_SIZE;
 __msp_stack_size__ = BL2_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_ns.ld b/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_ns.ld
index e372613..80d47fc 100644
--- a/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_ns.ld
+++ b/platform/ext/target/nuvoton/m2354/device/source/gcc/m2354_ns.ld
@@ -31,9 +31,6 @@
 __heap_size__  = NS_HEAP_SIZE;
 __stack_size__ = NS_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/stm/common/hal/template/gcc/appli_ns.ld b/platform/ext/target/stm/common/hal/template/gcc/appli_ns.ld
index 444b467..c1b1f81 100644
--- a/platform/ext/target/stm/common/hal/template/gcc/appli_ns.ld
+++ b/platform/ext/target/stm/common/hal/template/gcc/appli_ns.ld
@@ -31,9 +31,6 @@
 __heap_size__  = NS_HEAP_SIZE;
 __stack_size__ = NS_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/stm/common/hal/template/gcc/bl2.ld b/platform/ext/target/stm/common/hal/template/gcc/bl2.ld
index 619548f..a3ec4d4 100644
--- a/platform/ext/target/stm/common/hal/template/gcc/bl2.ld
+++ b/platform/ext/target/stm/common/hal/template/gcc/bl2.ld
@@ -40,10 +40,6 @@
 __heap_size__  = BL2_HEAP_SIZE;
 __msp_stack_size__ = BL2_MSP_STACK_SIZE;
 
-
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/stm/common/stm32h5xx/Device/Source/gcc/tfm_common_s.ld b/platform/ext/target/stm/common/stm32h5xx/Device/Source/gcc/tfm_common_s.ld
index 6c0f35e..ec93cff 100644
--- a/platform/ext/target/stm/common/stm32h5xx/Device/Source/gcc/tfm_common_s.ld
+++ b/platform/ext/target/stm/common/stm32h5xx/Device/Source/gcc/tfm_common_s.ld
@@ -39,9 +39,6 @@
 __heap_size__  = S_HEAP_SIZE;
 __msp_stack_size__ = S_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a libc_nano.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ext/target/stm/common/stm32u5xx/Device/Source/gcc/tfm_common_s.ld b/platform/ext/target/stm/common/stm32u5xx/Device/Source/gcc/tfm_common_s.ld
index 41f5835..2ecd15a 100644
--- a/platform/ext/target/stm/common/stm32u5xx/Device/Source/gcc/tfm_common_s.ld
+++ b/platform/ext/target/stm/common/stm32u5xx/Device/Source/gcc/tfm_common_s.ld
@@ -39,9 +39,6 @@
 __heap_size__  = S_HEAP_SIZE;
 __msp_stack_size__ = S_MSP_STACK_SIZE;
 
-/* Library configurations */
-GROUP(libgcc.a libc.a libm.a libnosys.a libc_nano.a)
-
 ENTRY(Reset_Handler)
 
 SECTIONS
diff --git a/platform/ns/toolchain_ns_GNUARM.cmake b/platform/ns/toolchain_ns_GNUARM.cmake
index 4e1ea0f..c03a73c 100644
--- a/platform/ns/toolchain_ns_GNUARM.cmake
+++ b/platform/ns/toolchain_ns_GNUARM.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -178,6 +178,7 @@
 
 add_compile_options(
     -specs=nano.specs
+    -specs=nosys.specs
     -Wall
     -Wno-format
     -Wno-return-type
@@ -189,7 +190,6 @@
     -fshort-enums
     -funsigned-char
     -mthumb
-    -nostdlib
     $<$<COMPILE_LANGUAGE:C>:-std=c99>
     $<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
     $<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${TFM_DEBUG_SYMBOLS}>>:-g>
@@ -199,6 +199,7 @@
 add_link_options(
     --entry=Reset_Handler
     -specs=nano.specs
+    -specs=nosys.specs
     LINKER:-check-sections
     LINKER:-fatal-warnings
     LINKER:--gc-sections
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index b6ae50e..4746f58 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -107,6 +107,7 @@
 
 add_compile_options(
     -specs=nano.specs
+    -specs=nosys.specs
     -Wall
     -Wno-format
     -Wno-return-type
@@ -118,7 +119,6 @@
     -fshort-enums
     -funsigned-char
     -mthumb
-    -nostdlib
     $<$<COMPILE_LANGUAGE:C>:-std=c99>
     $<$<COMPILE_LANGUAGE:CXX>:-std=c++11>
     $<$<OR:$<BOOL:${TFM_DEBUG_SYMBOLS}>,$<BOOL:${TFM_CODE_COVERAGE}>>:-g>
@@ -127,6 +127,7 @@
 add_link_options(
     --entry=Reset_Handler
     -specs=nano.specs
+    -specs=nosys.specs
     LINKER:-check-sections
     LINKER:-fatal-warnings
     LINKER:--gc-sections