From ec1c83081dd741bd18ca1821bf52535c444dc111 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 17 Mar 2014 23:14:38 +0800 Subject: [PATCH] Fix relocation of __bound_init When bound check is enabled, tcc tries to relocate a call to __bound_init in _init. This means that relocation (in tcc_add_bcheck) must be done after libtcc1.a (which countains __bound_init) is loaded but before crtn.o is loaded as this finalize _init. --- tccelf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tccelf.c b/tccelf.c index e7054a3f..ee00b035 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1373,8 +1373,6 @@ static inline int tcc_add_support(TCCState *s1, const char *filename) /* add tcc runtime libraries */ ST_FUNC void tcc_add_runtime(TCCState *s1) { - tcc_add_bcheck(s1); - /* add libc */ if (!s1->nostdlib) { tcc_add_library(s1, "c"); @@ -1386,6 +1384,14 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) #else tcc_add_support(s1, "libtcc1.a"); #endif + } + + /* tcc_add_bcheck tries to relocate a call to __bound_init in _init so + libtcc1.a must be loaded before for __bound_init to be defined and + crtn.o must be loaded after to not finalize _init too early. */ + tcc_add_bcheck(s1); + + if (!s1->nostdlib) { /* add crt end if not memory output */ if (s1->output_type != TCC_OUTPUT_MEMORY) tcc_add_crt(s1, "crtn.o"); -- 2.11.4.GIT