Skip to contentSkip to conversation

check for --exclude-libs

PATCH New Leon M. Busch-George 2 participants 4 messages Jan 26, 2024 – Feb 5, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 check for --exclude-libs

While writing to the dynsym is futile, the --exclude-libs options is not recognized by all linkers (e.g. riscv64-elf-ld.bfd)

---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Makefile +5 -0
index de4e73a..630e35f 100644
@@ -167,6 +167,9 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Check whether the linker supports --exclude-libs
+OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) "-Wl,--exclude-libs,ALL" -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
+
 # Check whether the compiler supports -m(no-)save-restore
 CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y)
 
@@ -375,7 +378,9 @@ ASFLAGS		+=	$(firmware-asflags-y)
 ARFLAGS		=	rcs
 
 ELFFLAGS	+=	$(USE_LD_FLAG)
+ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y)
 ELFFLAGS	+=	-Wl,--exclude-libs,ALL
+endif
 ELFFLAGS	+=	-Wl,--build-id=none
 ELFFLAGS	+=	$(platform-ldflags-y)
 ELFFLAGS	+=	$(firmware-ldflags-y)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 firmware: always create dynsym section

With a bare-metal linkers (e.g. riscv64-elf-ld), there exists no dynsym section.
The dynsym section is not used by OpenSBI but discarding it makes linkers with dynamic library support unhappy.

---
 firmware/fw_base.ldS | 5 +++++
 1 file changed, 5 insertions(+)
firmware/fw_base.ldS +5 -0
index c15ccdb..fb47984 100644
@@ -38,6 +38,11 @@
 		. = ALIGN(8);
 	}
 
+	.dynsym :
+	{
+		*(.dynsym)
+	}
+
 	. = ALIGN(0x1000); /* Ensure next section is page aligned */
 
 	.rela.dyn : {
Signature · 1 line
2.43.0
Applied
#2 lore raw

PATCH 2/2 firmware: always create dynsym section

Quoted 3 lines · On Fri, Jan 26, 2024 at 8:52?PM Leon M. Busch-George <[email protected]> wrote:

With a bare-metal linkers (e.g. riscv64-elf-ld), there exists no dynsym section.
The dynsym section is not used by OpenSBI but discarding it makes linkers with dynamic library support unhappy.

There is no Signed-off-by in the commit description.

I have taken care of the above at the time of merging this patch.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 28 lines
---
 firmware/fw_base.ldS | 5 +++++
 1 file changed, 5 insertions(+)
firmware/fw_base.ldS +5 -1
index c15ccdb..fb47984 100644
@@ -38,6 +38,11 @@
                . = ALIGN(8);
        }
 
+       .dynsym :
+       {
+               *(.dynsym)
+       }
+
        . = ALIGN(0x1000); /* Ensure next section is page aligned */
 
        .rela.dyn : {
--

2.43.0

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Applied
#3 lore raw

PATCH 1/2 check for --exclude-libs

In reply to Leon M. Busch-George
Quoted 2 lines · On Fri, Jan 26, 2024 at 8:52?PM Leon M. Busch-George <[email protected]> wrote:

While writing to the dynsym is futile, the --exclude-libs options is not recognized by all linkers (e.g. riscv64-elf-ld.bfd)

The patch subject needs "Makefile: " prefix. Also, there is no Signed-off-by in the commit description.

I have taken care of the above at the time of merging this patch.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 36 lines
---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Makefile +5 -1
index de4e73a..630e35f 100644
@@ -167,6 +167,9 @@ endif
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
+# Check whether the linker supports --exclude-libs
+OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) "-Wl,--exclude-libs,ALL" -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
+
 # Check whether the compiler supports -m(no-)save-restore
 CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y)
 
@@ -375,7 +378,9 @@ ASFLAGS             +=      $(firmware-asflags-y)
 ARFLAGS                =       rcs
 
 ELFFLAGS       +=      $(USE_LD_FLAG)
+ifeq ($(OPENSBI_LD_EXCLUDE_LIBS),y)
 ELFFLAGS       +=      -Wl,--exclude-libs,ALL
+endif
 ELFFLAGS       +=      -Wl,--build-id=none
 ELFFLAGS       +=      $(platform-ldflags-y)
 ELFFLAGS       +=      $(firmware-ldflags-y)
--

2.43.0

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi