[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] Add LoongArch64 basic support
From: |
Jinyang He |
Subject: |
Re: [PATCH 2/2] Add LoongArch64 basic support |
Date: |
Tue, 16 Jul 2024 09:59:02 +0800 |
User-agent: |
Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
On 2024-07-15 20:11, Camm Maguire wrote:
=============================================================================
0890adf6cf6aabd719c32f99c962356126919a14
Author: Camm Maguire<camm@transcendence.maguirefamily.org>
AuthorDate: Sun Jul 14 15:26:59 2024 -0400
Commit: Camm Maguire<camm@transcendence.maguirefamily.org>
CommitDate: Sun Jul 14 15:26:59 2024 -0400
Parent: 0fc02b307 debian version 2.7.0-23
Contained: Version_2_7_0pre master
Follows: Version_2_7_0pre26 (1)
Link libboot.so into pre_ images with ld to fix address, not dlopen
3 files changed, 10 insertions(+), 4 deletions(-)
gcl/makefile | 4 ++--
gcl/unixport/makefile | 4 ++--
gcl/unixport/sys_init.c | 6 ++++++
modified gcl/makefile
@@ -96,11 +96,11 @@ $(PORTDIR)/saved_pre_gcl: $(HDIR)cmpinclude.h
(cd $(ODIR); $(MAKE) all)
$(MAKE) $<
rm -f o/cmpinclude.h ; cp h/cmpinclude.h o
- cd $(@D) && $(MAKE) $(@F)
+ cd $(@D) && LD_LIBRARY_PATH=$(@D):$$LD_LIBRARY_PATH $(MAKE) $(@F)
touch $< $@
$(PORTDIR)/saved_gcl0: $(PORTDIR)/saved_pre_gcl $(HDIR)cmpinclude.h
- cd $(@D) && echo '(time (load "boot.lisp"))' | ../$<
+ cd $(@D) && echo '(time (load "boot.lisp"))' |
LD_LIBRARY_PATH=$(@D):$$LD_LIBRARY_PATH ../$<
cd $(@D) && $(MAKE) saved_gcl && mv saved_gcl $(@F)
$(PORTDIR)/saved_gcl1: $(PORTDIR)/saved_gcl0 $(HDIR)cmpinclude.h
modified gcl/unixport/makefile
@@ -155,9 +155,9 @@ ifeq ($(GNU_LD),1)
$(CC) $(LD_FLAGS) -o raw_$*$(EXE) $(filter %.o,$^) \
$(shell if echo $@ | grep -q gprof ; then echo "-pg"; else echo
""; fi) \
-rdynamic -L. $(EXTRA_LD_LIBS) $(LD_STACK_FLAGS) \
- -Wl,-Map raw_$*_map $(LD_LIBS_PRE) -l$* $(LD_LIBS_POST)
+ -Wl,-Map raw_$*_map $(LD_LIBS_PRE) -l$* $(LD_LIBS_POST) -lboot
else
- $(CC) $(LD_FLAGS) -o raw_$*$(EXE) $(filter %.o,$^) $(shell if grep -q gprof $@ ; then echo
"-pg"; else echo ""; fi) -L. $(EXTRA_LD_LIBS) $(LD_LIBS_PRE) -l$*
$(LD_LIBS_POST)
+ $(CC) $(LD_FLAGS) -o raw_$*$(EXE) $(filter %.o,$^) $(shell if grep -q gprof $@ ; then echo
"-pg"; else echo ""; fi) -L. $(EXTRA_LD_LIBS) $(LD_LIBS_PRE) -l$*
$(LD_LIBS_POST) -lboot
endif
map_%:
modified gcl/unixport/sys_init.c
@@ -20,6 +20,12 @@ gcl_init_init()
#endif
}
#endif
+
+#if defined(pre_gcl)
+ gcl_init_boot();/*Superfluous call to hard link boot.so into pre
+ image only, where it is used in raw_ and saved_
+ images and must have a fixed address*/
+#endif
lsp_init("lsp","gcl_export");
=============================================================================
It doesn't mmap to same.. The strace shows,
for raw_pre_gcl,
[...] Map libboot.so to memroy (, from dynamic linker ld.so.1)
openat(AT_FDCWD, "libboot.so", O_RDONLY|O_CLOEXEC) = 3
read(3, ...
statx(3, ...
mmap(NULL, 120864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0x7ffff01b0000
mmap(0x7ffff01c4000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x7ffff01c4000
mmap(0x7ffff01cc000, 6176, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff01cc000
close(3)
[...] Set rlimit_stack in gcl_init_alloc as gcl_alloc_initialized == 0
prlimit64(0, RLIMIT_STACK, {rlim_cur=RLIM64_INFINITY,
rlim_max=RLIM64_INFINITY}, NULL) = 0
[...] Set no_randomize and re-exec
personality(PER_LINUX|ADDR_NO_RANDOMIZE) = 0x400000
(PER_LINUX|READ_IMPLIES_EXEC)
personality(0xffffffff) = 0x40000
(PER_LINUX|ADDR_NO_RANDOMIZE)
brk(0x56ead0d5f) = 0x56ead0d5f
execve("raw_pre_gcl", ...
brk(NULL)
[...] Map libboot.so to memroy after re-exec
openat(AT_FDCWD, "libboot.so", O_RDONLY|O_CLOEXEC) = 3
read(3, ...
statx(3, ...
mmap(NULL, 120864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0x2aaaab114000
mmap(0x2aaaab128000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x2aaaab128000
mmap(0x2aaaab130000, 6176, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2aaaab130000
close(3)
[...] Then we can see it maps to another position. 0x2aaaab114000 vs
0x7ffff01b0000
for saved_pre_gcl,
[...] Map libboot.so to memroy
openat(AT_FDCWD, "libboot.so", O_RDONLY|O_CLOEXEC) = 3
read(3, ...
statx(3, ...
mmap(NULL, 120864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0x7ffff2a68000
mmap(0x7ffff2a7c000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x7ffff2a7c000
mmap(0x7ffff2a84000, 6176, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff2a84000
close(3)
[...] Because "gcl_alloc_initialized == 1", so it didn't call
gcl_init_alloc before. Re-exec.
personality(PER_LINUX|READ_IMPLIES_EXEC) = 0 (PER_LINUX)
personality(PER_LINUX|ADDR_NO_RANDOMIZE) = 0x400000
(PER_LINUX|READ_IMPLIES_EXEC)
personality(0xffffffff) = 0x40000
(PER_LINUX|ADDR_NO_RANDOMIZE)
brk(0x43930dd9) = 0x43930dd9
execve("saved_pre_gcl", ...
[...] Map libboot.so to memroy after re-exec
openat(AT_FDCWD, "libboot.so", O_RDONLY|O_CLOEXEC) = 3
read(3, ...
statx(3, ...
mmap(NULL, 120864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0x7ffff2a68000
mmap(0x7ffff2a7c000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x7ffff2a7c000
mmap(0x7ffff2a84000, 6176, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff2a84000
close(3)
So the patch didn't link libboot.so to fixed address becuase the
dynamic linker use mmap to map libboot.so, gcl_init_alloc also
influence the re-exec dynamic linker mmap range.
Thanks,
Jinyang
- [PATCH 0/2] Fix libX11 causing compile failed and add LoongArch64 support, Jinyang He, 2024/07/08
- [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/08
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/14
- Re: [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/14
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/15
- Re: [PATCH 2/2] Add LoongArch64 basic support,
Jinyang He <=
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/16
- Re: [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/17
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/17
- Re: [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/18
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/18
- Re: [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/19
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/19
- Re: [PATCH 2/2] Add LoongArch64 basic support, Jinyang He, 2024/07/19
- Re: [PATCH 2/2] Add LoongArch64 basic support, Camm Maguire, 2024/07/15
[PATCH 1/2] Fix libX11 early init causing mmap layout changed, Jinyang He, 2024/07/08