提交 768b82c6 编写于 作者: R Rich Felker

move call to dynamic linker stage-3 into stage-2 function

this move eliminates a duplicate "by-hand" symbol lookup loop from the
stage-1 code and replaces it with a call to find_sym, which can be
used once we're in stage 2. it reduces the size of the stage 1 code,
which is helpful because stage 1 will become the crt start file for
static-PIE executables, and it will allow stage 3 to access stage 2's
automatic storage, which will be important in an upcoming commit.
上级 967bcbf6
...@@ -51,7 +51,7 @@ enum { ...@@ -51,7 +51,7 @@ enum {
#define AUX_CNT 32 #define AUX_CNT 32
#define DYN_CNT 32 #define DYN_CNT 32
typedef void (*stage2_func)(unsigned char *); typedef void (*stage2_func)(unsigned char *, size_t *);
typedef _Noreturn void (*stage3_func)(size_t *); typedef _Noreturn void (*stage3_func)(size_t *);
#endif #endif
...@@ -84,16 +84,7 @@ void _dlstart_c(size_t *sp, size_t *dynv) ...@@ -84,16 +84,7 @@ void _dlstart_c(size_t *sp, size_t *dynv)
&& s[3]=='l' && s[4]=='s' && s[5]=='2' && !s[6]) && s[3]=='l' && s[4]=='s' && s[5]=='2' && !s[6])
break; break;
} }
((stage2_func)(base + syms[i].st_value))(base); ((stage2_func)(base + syms[i].st_value))(base, sp);
/* Call dynamic linker stage-3, __dls3 */
for (i=0; ;i++) {
const char *s = strings + syms[i].st_name;
if (s[0]=='_' && s[1]=='_' && s[2]=='d'
&& s[3]=='l' && s[4]=='s' && s[5]=='3' && !s[6])
break;
}
((stage3_func)(base + syms[i].st_value))(sp);
} }
#endif #endif
...@@ -1116,7 +1116,7 @@ static void update_tls_size() ...@@ -1116,7 +1116,7 @@ static void update_tls_size()
* linker itself, but some of the relocations performed may need to be * linker itself, but some of the relocations performed may need to be
* replaced later due to copy relocations in the main program. */ * replaced later due to copy relocations in the main program. */
void __dls2(unsigned char *base) void __dls2(unsigned char *base, size_t *sp)
{ {
Ehdr *ehdr = (void *)base; Ehdr *ehdr = (void *)base;
ldso.base = base; ldso.base = base;
...@@ -1134,6 +1134,12 @@ void __dls2(unsigned char *base) ...@@ -1134,6 +1134,12 @@ void __dls2(unsigned char *base)
ldso.relocated = 0; ldso.relocated = 0;
ldso.rel_update_got = 1; ldso.rel_update_got = 1;
/* Call dynamic linker stage-3, __dls3, looking it up
* symbolically as a barrier against moving the address
* load across the above relocation processing. */
struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
((stage3_func)(ldso.base+dls3_def.sym->st_value))(sp);
} }
/* Stage 3 of the dynamic linker is called with the dynamic linker/libc /* Stage 3 of the dynamic linker is called with the dynamic linker/libc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册