소스 검색

don't call null pointer if DT_INIT/DT_FINI are null

it's not clear to me why the linker even outputs these headers if they
are null, but apparently it does so. with the default startfiles, they
will never be null anyway, but this patch allows eliminating crti,
crtn, crtbegin, and crtend (leaving only crt1) if the toolchain is
using init_array/fini_array (or for a C-only, no-ctor environment).
Rich Felker 11 년 전
부모
커밋
d0c6cb05e7
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      src/ldso/dynlink.c

+ 2 - 2
src/ldso/dynlink.c

@@ -715,7 +715,7 @@ static void do_fini()
 			while (n--) ((void (*)(void))*--fn)();
 		}
 #ifndef NO_LEGACY_INITFINI
-		if (dyn[0] & (1<<DT_FINI))
+		if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
 			((void (*)(void))(p->base + dyn[DT_FINI]))();
 #endif
 	}
@@ -738,7 +738,7 @@ static void do_init_fini(struct dso *p)
 			fini_head = p;
 		}
 #ifndef NO_LEGACY_INITFINI
-		if (dyn[0] & (1<<DT_INIT))
+		if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
 			((void (*)(void))(p->base + dyn[DT_INIT]))();
 #endif
 		if (dyn[0] & (1<<DT_INIT_ARRAY)) {