From b33abcf6020b86e8fcabfca0722cf3811045cdb4 Mon Sep 17 00:00:00 2001 From: asterich Date: Fri, 29 Sep 2023 22:51:42 +0800 Subject: [PATCH 1/6] add article: 20230929-elf2flt-fix-install.md --- articles/20230929-elf2flt-fix-install.md | 179 +++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 articles/20230929-elf2flt-fix-install.md diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md new file mode 100644 index 0000000..bac19bd --- /dev/null +++ b/articles/20230929-elf2flt-fix-install.md @@ -0,0 +1,179 @@ +> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces toc urls refs pangu]
+> Author: Odysseus <320873791@qq.com>
+> Date: 2023/09/19
+> Revisor: walimis <>
+> Project: [RISC-V Linux 内核剖析](https://gitee.com/tinylab/riscv-linux)
+> Proposal: [为 ELF2FLT 完善独立编译与安装支持](https://gitee.com/tinylab/riscv-linux/issues/I79PO2)
+> Sponsor: PLCT Lab, ISCAS + +# elf2flt 在 RISC-V 64位下的独立编译和安装支持 + +## 前言 + +elf2flt 在设计之初是与 Buildroot 工具链结合使用的,但是它实际上也能搭配本机自带的工具链(例如 `/usr/bin/gcc` )使用。然而,原先的 elf2flt 安装过程存在问题,使得它无法正确安装到本机,与本机工具链结合使用。下面我们以 riscv-lab 下的安装过程为例,来看看其原因何在。 + +## 过程 + +首先我们克隆下来原来的 git 仓库,然后开始构建: +```sh +$ git clone https://gitee.com/tinylab/elf2flt +$ cd elf2flt +$ ./configure --target=riscv64-linux-gnu -with-bfd-include-dir=/usr/include/ \ +> --with-binutils-include-dir=/usr/include/ \ +> --with-libbfd=/usr/lib/riscv64-linux-gnu/libbfd.a \ +> --with-libiberty=/usr/lib/riscv64-linux-gnu/libiberty.a \ +> --disable-werror --build=riscv64-linux-gnu +$ make +$ sudo make install +``` + +它会报错,如下: +```sh +/usr/bin/install -c -d /usr/local/bin /usr/local/riscv64-linux-gnu/bin /usr/local/riscv64-linux-gnu/lib +/usr/bin/install -c -m 755 flthdr /usr/local/bin/riscv64-linux-gnu-flthdr +/usr/bin/install -c -m 755 flthdr /usr/local/riscv64-linux-gnu/bin/flthdr +/usr/bin/install -c -m 755 elf2flt /usr/local/bin/riscv64-linux-gnu-elf2flt +/usr/bin/install -c -m 755 elf2flt /usr/local/riscv64-linux-gnu/bin/elf2flt +[ -f /usr/local/bin/riscv64-linux-gnu-ld.real ] || \ + mv /usr/local/bin/riscv64-linux-gnu-ld /usr/local/bin/riscv64-linux-gnu-ld.real +/usr/bin/mv: cannot stat '/usr/local/bin/riscv64-linux-gnu-ld': No such file or directory +make: *** [Makefile:114: install] Error 1 +``` + +这里我们可以对应到原 `Makefile.in` 的以下部分: +```makefile +install: + $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) + [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) + [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) +``` + +这个 `$(bindir)` 和 `$(target_bindir)` 分别是什么呢?我们在 `Makefile.in` 中寻找,发现它们的值如下: +```makefile +bindir = @bindir@ + +# ... + +target_bindir = $(prefix)/$(TARGET)/bin +``` + +这个 `$(prefix)` 在 `./configure` 中被赋默认值: +```sh +ac_default_prefix=/usr/local + +# ... + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' +``` + +因此这里的 `riscv64-linux-gnu-ld` 默认会在 `/usr/local/bin` 下查找,但是那里显然没有,这意味着我们很可能要创建一个软链接,或者直接将别处 `riscv64-linux-gnu-ld` 复制到该目录下面。我们使用 `which` 命令查看我们的交叉工具链在哪里: + +```sh +$ which riscv64-linux-gnu-gcc +/usr/bin/riscv64-linux-gnu-gcc + +$ which riscv64-linux-gnu-ld +/usr/bin/riscv64-linux-gnu-ld +``` + +可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,后面可能会考虑在配置文件中增加工具链路径的配置选项。 + +我们对此做出如下修改: +```diff +install: + $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) ++ cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld ++ cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ++ mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old ++ ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) +``` + +另外,在 `$(bindir)/` 下的 elf2flt 和 flthdr 实际上是带前缀的,但是它们在被调用时是不带前缀的,因此会出现形如 ` ld (ld-elf2flt): execvp: No such file or directory` 的错误。这里需要把链接加上: +```diff +install: + $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) + cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld + cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) + [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) + mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld ++ ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) ++ ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) +``` + +到了这一步重新进行安装,过程看起来比较顺利。然而我们编译一个简单的 hello-world 时,仍然发生了` ld (ld-elf2flt): execvp: No such file or directory`的错误,如下: +```sh +$ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o +ld (ld-elf2flt): execvp: No such file or directory +collect2: error: ld returned 1 exit status +``` + +经查,发现原因是 `$(target_bindir)/` 下面没有程序 `nm` ,导致 `ld` 在调用它时出现问题。因此我们加上一句链接: +```diff +install: + $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) + cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld + cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) + [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) + mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld + ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) + ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) ++ ln -s /usr/bin/$(TARGET)-nm $(DESTDIR)$(target_bindir)/nm + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) +``` + +至此问题解决, `riscv64-linux-gnu-gcc` 能够编译出正常的 bFLT 程序: +```sh +$ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o +$ +``` + +## 总结 + +elf2flt 独立编译和安装存在的问题主要是安装部分,因此在修改`Makefile.in`后得以解决。消除 Buildroot 的依赖则是另一个问题,需要仔细观察 Buildroot 交叉编译时依赖了哪些库和头文件,并且想办法去除这些依赖,这里不详细说明。 + +## 参考资料 + +- [https://gitee.com/tinylab/riscv-linux/blob/master/articles/20230919-elf2flt-flt-analysis-0.md][001] +- [https://gitee.com/tinylab/elf2flt][002] + +[001]: https://gitee.com/tinylab/riscv-linux/blob/master/articles/20230919-elf2flt-flt-analysis-0.md +[002]: https://gitee.com/tinylab/elf2flt \ No newline at end of file -- Gitee From b1fb0bafd56814e2129bc9255df91cc026538b8c Mon Sep 17 00:00:00 2001 From: asterich Date: Fri, 29 Sep 2023 22:53:40 +0800 Subject: [PATCH 2/6] elf2flt-fix-install.md: commit correct result of tinycorrect Signed-off-by: asterich --- articles/20230929-elf2flt-fix-install.md | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md index bac19bd..9fd4f97 100644 --- a/articles/20230929-elf2flt-fix-install.md +++ b/articles/20230929-elf2flt-fix-install.md @@ -1,4 +1,4 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces toc urls refs pangu]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces codeblock codeinline pangu]
> Author: Odysseus <320873791@qq.com>
> Date: 2023/09/19
> Revisor: walimis <>
@@ -6,15 +6,16 @@ > Proposal: [为 ELF2FLT 完善独立编译与安装支持](https://gitee.com/tinylab/riscv-linux/issues/I79PO2)
> Sponsor: PLCT Lab, ISCAS -# elf2flt 在 RISC-V 64位下的独立编译和安装支持 +# elf2flt 在 RISC-V 64 位下的独立编译和安装支持 ## 前言 -elf2flt 在设计之初是与 Buildroot 工具链结合使用的,但是它实际上也能搭配本机自带的工具链(例如 `/usr/bin/gcc` )使用。然而,原先的 elf2flt 安装过程存在问题,使得它无法正确安装到本机,与本机工具链结合使用。下面我们以 riscv-lab 下的安装过程为例,来看看其原因何在。 +elf2flt 在设计之初是与 Buildroot 工具链结合使用的,但是它实际上也能搭配本机自带的工具链(例如 `/usr/bin/gcc`)使用。然而,原先的 elf2flt 安装过程存在问题,使得它无法正确安装到本机,与本机工具链结合使用。下面我们以 riscv-lab 下的安装过程为例,来看看其原因何在。 ## 过程 首先我们克隆下来原来的 git 仓库,然后开始构建: + ```sh $ git clone https://gitee.com/tinylab/elf2flt $ cd elf2flt @@ -28,6 +29,7 @@ $ sudo make install ``` 它会报错,如下: + ```sh /usr/bin/install -c -d /usr/local/bin /usr/local/riscv64-linux-gnu/bin /usr/local/riscv64-linux-gnu/lib /usr/bin/install -c -m 755 flthdr /usr/local/bin/riscv64-linux-gnu-flthdr @@ -41,6 +43,7 @@ make: *** [Makefile:114: install] Error 1 ``` 这里我们可以对应到原 `Makefile.in` 的以下部分: + ```makefile install: $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) @@ -58,6 +61,7 @@ install: ``` 这个 `$(bindir)` 和 `$(target_bindir)` 分别是什么呢?我们在 `Makefile.in` 中寻找,发现它们的值如下: + ```makefile bindir = @bindir@ @@ -67,6 +71,7 @@ target_bindir = $(prefix)/$(TARGET)/bin ``` 这个 `$(prefix)` 在 `./configure` 中被赋默认值: + ```sh ac_default_prefix=/usr/local @@ -90,6 +95,7 @@ $ which riscv64-linux-gnu-ld 可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,后面可能会考虑在配置文件中增加工具链路径的配置选项。 我们对此做出如下修改: + ```diff install: $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) @@ -106,7 +112,8 @@ install: $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` -另外,在 `$(bindir)/` 下的 elf2flt 和 flthdr 实际上是带前缀的,但是它们在被调用时是不带前缀的,因此会出现形如 ` ld (ld-elf2flt): execvp: No such file or directory` 的错误。这里需要把链接加上: +另外,在 `$(bindir)/` 下的 elf2flt 和 flthdr 实际上是带前缀的,但是它们在被调用时是不带前缀的,因此会出现形如 `ld (ld-elf2flt): execvp: No such file or directory` 的错误。这里需要把链接加上: + ```diff install: $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) @@ -129,14 +136,16 @@ install: $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` -到了这一步重新进行安装,过程看起来比较顺利。然而我们编译一个简单的 hello-world 时,仍然发生了` ld (ld-elf2flt): execvp: No such file or directory`的错误,如下: +到了这一步重新进行安装,过程看起来比较顺利。然而我们编译一个简单的 hello-world 时,仍然发生了 `ld (ld-elf2flt): execvp: No such file or directory` 的错误,如下: + ```sh $ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o ld (ld-elf2flt): execvp: No such file or directory collect2: error: ld returned 1 exit status ``` -经查,发现原因是 `$(target_bindir)/` 下面没有程序 `nm` ,导致 `ld` 在调用它时出现问题。因此我们加上一句链接: +经查,发现原因是 `$(target_bindir)/` 下面没有程序 `nm`,导致 `ld` 在调用它时出现问题。因此我们加上一句链接: + ```diff install: $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) @@ -160,15 +169,16 @@ install: $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` -至此问题解决, `riscv64-linux-gnu-gcc` 能够编译出正常的 bFLT 程序: +至此问题解决,`riscv64-linux-gnu-gcc` 能够编译出正常的 bFLT 程序: + ```sh $ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o -$ +$ ``` ## 总结 -elf2flt 独立编译和安装存在的问题主要是安装部分,因此在修改`Makefile.in`后得以解决。消除 Buildroot 的依赖则是另一个问题,需要仔细观察 Buildroot 交叉编译时依赖了哪些库和头文件,并且想办法去除这些依赖,这里不详细说明。 +elf2flt 独立编译和安装存在的问题主要是安装部分,因此在修改 `Makefile.in` 后得以解决。消除 Buildroot 的依赖则是另一个问题,需要仔细观察 Buildroot 交叉编译时依赖了哪些库和头文件,并且想办法去除这些依赖,这里不详细说明。 ## 参考资料 @@ -176,4 +186,4 @@ elf2flt 独立编译和安装存在的问题主要是安装部分,因此在修 - [https://gitee.com/tinylab/elf2flt][002] [001]: https://gitee.com/tinylab/riscv-linux/blob/master/articles/20230919-elf2flt-flt-analysis-0.md -[002]: https://gitee.com/tinylab/elf2flt \ No newline at end of file +[002]: https://gitee.com/tinylab/elf2flt -- Gitee From 308a0f1863ee450990df9b11f61a0b5f3f2e02ac Mon Sep 17 00:00:00 2001 From: asterich Date: Sat, 30 Sep 2023 05:08:58 +0800 Subject: [PATCH 3/6] fix article 20230929-elf2flt-fix-install: edited content according to new elf2flt installation process Signed-off-by: asterich --- articles/20230929-elf2flt-fix-install.md | 180 +++++++++++++++++++---- 1 file changed, 152 insertions(+), 28 deletions(-) diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md index 9fd4f97..5276825 100644 --- a/articles/20230929-elf2flt-fix-install.md +++ b/articles/20230929-elf2flt-fix-install.md @@ -80,9 +80,19 @@ ac_default_prefix=/usr/local test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# ... + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' ``` -因此这里的 `riscv64-linux-gnu-ld` 默认会在 `/usr/local/bin` 下查找,但是那里显然没有,这意味着我们很可能要创建一个软链接,或者直接将别处 `riscv64-linux-gnu-ld` 复制到该目录下面。我们使用 `which` 命令查看我们的交叉工具链在哪里: +因此这里的 `riscv64-linux-gnu-ld` 默认会在 `/usr/local/bin` 下查找,但是那里显然没有,这意味着我们很可能要创建一个软链接,或者直接将别处 `riscv64-linux-gnu-ld` 复制到 `$(bindir)` 代表的目录下面。我们使用 `which` 命令查看我们的交叉工具链在哪里: ```sh $ which riscv64-linux-gnu-gcc @@ -92,26 +102,102 @@ $ which riscv64-linux-gnu-ld /usr/bin/riscv64-linux-gnu-ld ``` -可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,后面可能会考虑在配置文件中增加工具链路径的配置选项。 +可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,需要额外添加配置选项,指定工具链的可执行程序路径。在这里,我采用修改 `configure.ac` 的方案,通过往 `configure.ac` 中添加相应的配置选项达成目的。具体而言,我在 `configure.ac` 中加入 `--with-toolchain-bindir=` 这一配置选项,并把其值传递给变量 `$(toolchain_bindir)`,供 `Makefile.in` 使用。 -我们对此做出如下修改: +`configure.ac` 中修改如下: ```diff +@@ -1,6 +1,12 @@ + dnl Process this file with autoconf to produce a configure script. + AC_INIT(elf2flt.c) + ++AC_ARG_WITH(toolchain-bindir, ++ AS_HELP_STRING([--with-toolchain-bindir=], [path to installed toolchain]), ++ [ ac_toolchain_bindir=$withval ], ++ [ ac_toolchain_bindir=NONE ] ++) ++ + AC_ARG_WITH(zlib-prefix, + AS_HELP_STRING([--with-zlib-prefix=], [path to installed zlib]), + [ ac_zlib_prefix=$withval ], + + +@@ -137,6 +143,11 @@ + else + LIBS="$ac_libbfd $LIBS" + fi + ++toolchain_bindir= ++if test "$ac_toolchain_bindir" != "NONE"; then ++ toolchain_bindir=$(cd "$ac_toolchain_bindir" && pwd) ++fi ++ + bfd_include_dir= + if test "$ac_bfd_include_dir" != "NONE"; then + bfd_include_dir=$(cd "$ac_bfd_include_dir" && pwd) + + +@@ -158,6 +169,16 @@ + if test "$ac_binutils_ldscript_dir" = "NONE"; then + fi + binutils_ldscript_dir="$ac_binutils_ldscript_dir" + ++if test "$ac_toolchain_bindir" = "NONE" ; then ++ AC_MSG_ERROR([ ++You need to specify the location of the installed toolchain. ++ ++Run configure again specifying this option: ++ ++ ./configure --target= --with-toolchain-bindir= --with-bfd-include-dir= --with-libbfd= --with-libiberty= ++]) ++fi ++ + if test "$ac_libbfd" = "NONE" -o "$ac_libiberty" = "NONE" ; then + AC_MSG_ERROR([ + + +@@ -258,6 +279,7 @@ AC_SUBST(target_alias) + AC_SUBST(target_cpu) + AC_SUBST(target_os) + AC_SUBST(target_vendor) ++AC_SUBST(toolchain_bindir) + AC_SUBST(bfd_include_dir) +``` + +而后,对于 `Makefile.in`,我们做出如下修改: + +```diff +@@ -8,6 +8,7 @@ +exec_prefix = @exec_prefix@ + bindir = @bindir@ + libdir = @libdir@ + includedir = @includedir@ ++toolchain_bindir = @toolchain_bindir@ + + CC = @CC@ + CPU = @target_cpu@ + + +@@ -111,12 +112,19 @@ install: - $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(target_bindir) $(DESTDIR)$(target_libdir) - $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_FLTHDR) - $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) - $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) - $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) -+ cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld -+ cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld - [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ - mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) -+ mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old -+ ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld - $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) + $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) + $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) ++ cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld ++ cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) + [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ + mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) ++ mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old ++ ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` +这里的主要改动是将工具链原先的 `ld` 程序保存起来,再将 `ld` 链接到已整合好 elf2flt 后的链接器上。 + 另外,在 `$(bindir)/` 下的 elf2flt 和 flthdr 实际上是带前缀的,但是它们在被调用时是不带前缀的,因此会出现形如 `ld (ld-elf2flt): execvp: No such file or directory` 的错误。这里需要把链接加上: ```diff @@ -121,25 +207,51 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) - cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld - cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld + cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) - mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old - ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld + mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld + ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) + ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` -到了这一步重新进行安装,过程看起来比较顺利。然而我们编译一个简单的 hello-world 时,仍然发生了 `ld (ld-elf2flt): execvp: No such file or directory` 的错误,如下: +到了这一步重新进行安装: ```sh -$ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o +$ aclocal +$ autoupdate +$ autoconf +$ ./configure --with-toolchain-bindir=/usr/bin --target=riscv64-linux-gnu -with-bfd-include-dir=/usr/include/ \ +> --with-binutils-include-dir=/usr/include/ \ +> --with-libbfd=/usr/lib/riscv64-linux-gnu/libbfd.a \ +> --with-libiberty=/usr/lib/riscv64-linux-gnu/libiberty.a \ +> --disable-werror --build=riscv64-linux-gnu +$ make +$ sudo make install +``` + +过程看起来比较顺利。然而我们编译一个简单的 hello-world 时,仍然发生了 `ld (ld-elf2flt): execvp: No such file or directory` 的错误,如下: + +```sh +$ riscv64-linux-gnu-gcc -nostdinc -nostdlib \ +> -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include \ +> -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed \ +> -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include \ +> /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o \ +> -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc \ +> -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib \ +> -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o + ld (ld-elf2flt): execvp: No such file or directory collect2: error: ld returned 1 exit status ``` @@ -153,27 +265,39 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) - cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld - cp /usr/bin/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld + cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) - mv /usr/bin/$(TARGET)-ld /usr/bin/$(TARGET)-ld_old - ln -s $(DESTDIR)$(target_bindir)/ld /usr/bin/$(TARGET)-ld + mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) -+ ln -s /usr/bin/$(TARGET)-nm $(DESTDIR)$(target_bindir)/nm ++ ln -s $(toolchain_bindir)/$(TARGET)-nm $(DESTDIR)$(target_bindir)/nm $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` 至此问题解决,`riscv64-linux-gnu-gcc` 能够编译出正常的 bFLT 程序: ```sh -$ riscv64-linux-gnu-gcc -nostdinc -nostdlib -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o -$ +$ riscv64-linux-gnu-gcc -nostdinc -nostdlib \ +> -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include \ +> -I/usr/bin/../lib/gcc/riscv64-linux-gnu/11/include-fixed \ +> -I/labs/riscv-lab/buildroot/output/host/riscv64-buildroot-linux-uclibc/sysroot/usr/include \ +> /labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib/crt1.o \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crti.o /usr/lib/gcc/riscv64-linux-gnu/11/crtbeginT.o \ +> -L/usr/lib/gcc/riscv64-linux-gnu/11 -L/usr/lib/gcc \ +> -L/labs/riscv-lab/buildroot/output/build/uclibc-1.0.44/lib \ +> -Wl,--build-id=none -Wl,-elf2flt=-r -o hello-b-gcc hello.c --static -lc -lgcc \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crtend.o \ +> /usr/lib/gcc/riscv64-linux-gnu/11/crtn.o + +$ ls +hello-b-gcc hello-b-gcc.gdb ``` ## 总结 -- Gitee From 4f5ce1dfd2361e46a5d5e3d516adc7fe6781eb67 Mon Sep 17 00:00:00 2001 From: asterich Date: Sat, 30 Sep 2023 05:11:14 +0800 Subject: [PATCH 4/6] elf2flt-fix-install.md: commit correct result of tinycorrect-codeblock Signed-off-by: asterich --- articles/20230929-elf2flt-fix-install.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md index 5276825..55381a7 100644 --- a/articles/20230929-elf2flt-fix-install.md +++ b/articles/20230929-elf2flt-fix-install.md @@ -1,4 +1,4 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces codeblock codeinline pangu]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces newline toc comments codeblock]
> Author: Odysseus <320873791@qq.com>
> Date: 2023/09/19
> Revisor: walimis <>
@@ -121,7 +121,6 @@ $ which riscv64-linux-gnu-ld AS_HELP_STRING([--with-zlib-prefix=], [path to installed zlib]), [ ac_zlib_prefix=$withval ], - @@ -137,6 +143,11 @@ else LIBS="$ac_libbfd $LIBS" @@ -136,7 +135,6 @@ $ which riscv64-linux-gnu-ld if test "$ac_bfd_include_dir" != "NONE"; then bfd_include_dir=$(cd "$ac_bfd_include_dir" && pwd) - @@ -158,6 +169,16 @@ if test "$ac_binutils_ldscript_dir" = "NONE"; then fi @@ -155,7 +153,6 @@ $ which riscv64-linux-gnu-ld if test "$ac_libbfd" = "NONE" -o "$ac_libiberty" = "NONE" ; then AC_MSG_ERROR([ - @@ -258,6 +279,7 @@ AC_SUBST(target_alias) AC_SUBST(target_cpu) AC_SUBST(target_os) @@ -177,7 +174,6 @@ exec_prefix = @exec_prefix@ CC = @CC@ CPU = @target_cpu@ - @@ -111,12 +112,19 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) -- Gitee From 1b28f88b73b754b0595b42a1e3ba24a960dc5c72 Mon Sep 17 00:00:00 2001 From: asterich Date: Sat, 21 Oct 2023 23:46:23 +0800 Subject: [PATCH 5/6] fix article 20230929-elf2flt-fix-install: edited content according to new elf2flt installation process Signed-off-by: asterich --- articles/20230929-elf2flt-fix-install.md | 84 ++++-------------------- 1 file changed, 12 insertions(+), 72 deletions(-) diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md index 55381a7..cab6484 100644 --- a/articles/20230929-elf2flt-fix-install.md +++ b/articles/20230929-elf2flt-fix-install.md @@ -102,66 +102,9 @@ $ which riscv64-linux-gnu-ld /usr/bin/riscv64-linux-gnu-ld ``` -可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,需要额外添加配置选项,指定工具链的可执行程序路径。在这里,我采用修改 `configure.ac` 的方案,通过往 `configure.ac` 中添加相应的配置选项达成目的。具体而言,我在 `configure.ac` 中加入 `--with-toolchain-bindir=` 这一配置选项,并把其值传递给变量 `$(toolchain_bindir)`,供 `Makefile.in` 使用。 +可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,所以我们看一下有无相关的配置选项。实际上,我们在之前的探寻过程中已经发现了一个可用的变量: `$prefix` 。在 `./configure` 里面,`$prefix` 变量被追加到 `$bindir` 的开头,因此我们只需使用 `$bindir` 。另外, elf2flt 中有一个变量 `$DESTDIR` ,是指定 Buildroot 中 host 工具链的,为了保持与 Buildroot 的兼容性,我们还需要在 `$bindir` 前面加上这个变量。 -`configure.ac` 中修改如下: - -```diff -@@ -1,6 +1,12 @@ - dnl Process this file with autoconf to produce a configure script. - AC_INIT(elf2flt.c) - -+AC_ARG_WITH(toolchain-bindir, -+ AS_HELP_STRING([--with-toolchain-bindir=], [path to installed toolchain]), -+ [ ac_toolchain_bindir=$withval ], -+ [ ac_toolchain_bindir=NONE ] -+) -+ - AC_ARG_WITH(zlib-prefix, - AS_HELP_STRING([--with-zlib-prefix=], [path to installed zlib]), - [ ac_zlib_prefix=$withval ], - -@@ -137,6 +143,11 @@ - else - LIBS="$ac_libbfd $LIBS" - fi - -+toolchain_bindir= -+if test "$ac_toolchain_bindir" != "NONE"; then -+ toolchain_bindir=$(cd "$ac_toolchain_bindir" && pwd) -+fi -+ - bfd_include_dir= - if test "$ac_bfd_include_dir" != "NONE"; then - bfd_include_dir=$(cd "$ac_bfd_include_dir" && pwd) - -@@ -158,6 +169,16 @@ - if test "$ac_binutils_ldscript_dir" = "NONE"; then - fi - binutils_ldscript_dir="$ac_binutils_ldscript_dir" - -+if test "$ac_toolchain_bindir" = "NONE" ; then -+ AC_MSG_ERROR([ -+You need to specify the location of the installed toolchain. -+ -+Run configure again specifying this option: -+ -+ ./configure --target= --with-toolchain-bindir= --with-bfd-include-dir= --with-libbfd= --with-libiberty= -+]) -+fi -+ - if test "$ac_libbfd" = "NONE" -o "$ac_libiberty" = "NONE" ; then - AC_MSG_ERROR([ - -@@ -258,6 +279,7 @@ AC_SUBST(target_alias) - AC_SUBST(target_cpu) - AC_SUBST(target_os) - AC_SUBST(target_vendor) -+AC_SUBST(toolchain_bindir) - AC_SUBST(bfd_include_dir) -``` - -而后,对于 `Makefile.in`,我们做出如下修改: +综上,对于 `Makefile.in`,我们做出如下修改: ```diff @@ -8,6 +8,7 @@ @@ -179,16 +122,15 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) -+ cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld -+ cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld ++ cp $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) -+ mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old -+ ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld ++ mv $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld_old ++ ln -s $(DESTDIR)$(target_bindir)/ld $(DESTDIR)$(bindir)/$(TARGET)-ld $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` @@ -203,16 +145,15 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) - cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld - cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + cp $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) - mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old - ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld + mv $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld $(DESTDIR)$(bindir)/$(TARGET)-ld + ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) + ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) @@ -261,19 +202,18 @@ install: $(INSTALL) -m 755 $(PROG_FLTHDR) $(DESTDIR)$(target_bindir)/$(PROG_FLTHDR) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-$(PROG_ELF2FLT) $(INSTALL) -m 755 $(PROG_ELF2FLT) $(DESTDIR)$(target_bindir)/$(PROG_ELF2FLT) - cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld - cp $(toolchain_bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld + cp $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(target_bindir)/ld [ -f $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(DESTDIR)$(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(DESTDIR)$(target_bindir)/ld$(EXEEXT) $(DESTDIR)$(target_bindir)/ld.real$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(bindir)/$(TARGET)-ld$(EXEEXT) $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(DESTDIR)$(target_bindir)/ld$(EXEEXT) - mv $(toolchain_bindir)/$(TARGET)-ld $(toolchain_bindir)/$(TARGET)-ld_old - ln -s $(DESTDIR)$(target_bindir)/ld $(toolchain_bindir)/$(TARGET)-ld + mv $(DESTDIR)$(bindir)/$(TARGET)-ld $(DESTDIR)$(bindir)/$(TARGET)-ld_old + ln -s $(DESTDIR)$(target_bindir)/ld $(DESTDIR)$(bindir)/$(TARGET)-ld ln -s $(DESTDIR)$(bindir)/$(TARGET)-elf2flt$(EXEEXT) $(DESTDIR)$(bindir)/elf2flt$(EXEEXT) ln -s $(DESTDIR)$(bindir)/$(TARGET)-flthdr$(EXEEXT) $(DESTDIR)$(bindir)/flthdr$(EXEEXT) -+ ln -s $(toolchain_bindir)/$(TARGET)-nm $(DESTDIR)$(target_bindir)/nm ++ ln -s $(DESTDIR)$(bindir)/$(TARGET)-nm $(DESTDIR)$(target_bindir)/nm $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) ``` -- Gitee From 915576075fc058eb13c60c96c1d3663cd9933462 Mon Sep 17 00:00:00 2001 From: asterich Date: Sat, 21 Oct 2023 23:47:29 +0800 Subject: [PATCH 6/6] elf2flt-fix-install.md: commit correct result of tinycorrect-spaces Signed-off-by: asterich --- articles/20230929-elf2flt-fix-install.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/articles/20230929-elf2flt-fix-install.md b/articles/20230929-elf2flt-fix-install.md index cab6484..5af46ac 100644 --- a/articles/20230929-elf2flt-fix-install.md +++ b/articles/20230929-elf2flt-fix-install.md @@ -1,4 +1,4 @@ -> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces newline toc comments codeblock]
+> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces]
> Author: Odysseus <320873791@qq.com>
> Date: 2023/09/19
> Revisor: walimis <>
@@ -102,7 +102,7 @@ $ which riscv64-linux-gnu-ld /usr/bin/riscv64-linux-gnu-ld ``` -可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,所以我们看一下有无相关的配置选项。实际上,我们在之前的探寻过程中已经发现了一个可用的变量: `$prefix` 。在 `./configure` 里面,`$prefix` 变量被追加到 `$bindir` 的开头,因此我们只需使用 `$bindir` 。另外, elf2flt 中有一个变量 `$DESTDIR` ,是指定 Buildroot 中 host 工具链的,为了保持与 Buildroot 的兼容性,我们还需要在 `$bindir` 前面加上这个变量。 +可以看到工具链调用的是 `/usr/bin` 下的。这里每个人的情况可能会有所不同,所以我们看一下有无相关的配置选项。实际上,我们在之前的探寻过程中已经发现了一个可用的变量:`$prefix`。在 `./configure` 里面,`$prefix` 变量被追加到 `$bindir` 的开头,因此我们只需使用 `$bindir`。另外,elf2flt 中有一个变量 `$DESTDIR`,是指定 Buildroot 中 host 工具链的,为了保持与 Buildroot 的兼容性,我们还需要在 `$bindir` 前面加上这个变量。 综上,对于 `Makefile.in`,我们做出如下修改: @@ -113,7 +113,7 @@ exec_prefix = @exec_prefix@ libdir = @libdir@ includedir = @includedir@ +toolchain_bindir = @toolchain_bindir@ - + CC = @CC@ CPU = @target_cpu@ -- Gitee