History

tccelf: load objects first

It seems to make sense to load any helper objects (such as bcheck.o) first, and then load standard libraries. 29 insertions(+), 29 deletions(-)

grischka committed 4 years ago

Commit d653cf01 parent 7d6979d1 file · +29 −29Browse files

Unified · Split

tccelf.c+29−29
@@ -1471,35 +1471,23 @@ static void tcc_tcov_add_file(TCCState *s1, const char *filename) · 1470 unmodified lines
14711471 ST_FUNC void tcc_add_runtime(TCCState *s1)
14721472 {
14731473 s1->filetype = 0;
1474+
14741475 #ifdef CONFIG_TCC_BCHECK
14751476 tcc_add_bcheck(s1);
14761477 #endif
14771478 tcc_add_pragma_libs(s1);
1479+
14781480 /* add libc */
14791481 if (!s1->nostdlib) {
1480− if (s1->option_pthread)
1481− tcc_add_library_err(s1, "pthread");
1482− tcc_add_library_err(s1, "c");
1483−#ifdef TCC_LIBGCC
1484− if (!s1->static_link) {
1485− if (TCC_LIBGCC[0] == '/')
1486− tcc_add_file(s1, TCC_LIBGCC);
1487− else
1488− tcc_add_dll(s1, TCC_LIBGCC, 0);
1489− }
1490−#endif
1491−#if TCC_TARGET_ARM && TARGETOS_FreeBSD
1492− tcc_add_library_err(s1, "gcc_s"); // unwind code
1493−#endif
1482+ int lpthread = s1->option_pthread;
1483+
14941484 #ifdef CONFIG_TCC_BCHECK
14951485 if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
1496− tcc_add_library_err(s1, "pthread");
1497−#if !TARGETOS_OpenBSD && !TARGETOS_NetBSD
1498− tcc_add_library_err(s1, "dl");
1499−#endif
15001486 tcc_add_support(s1, "bcheck.o");
1501− if (s1->static_link)
1502− tcc_add_library_err(s1, "c");
1487+# if !(TARGETOS_OpenBSD || TARGETOS_NetBSD)
1488+ tcc_add_library_err(s1, "dl");
1489+# endif
1490+ lpthread = 1;
15031491 }
15041492 #endif
15051493 #ifdef CONFIG_TCC_BACKTRACE
@@ -1511,28 +1499,40 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 5 unmodified lines
15111499 if (s1->output_type != TCC_OUTPUT_MEMORY)
15121500 tcc_add_btstub(s1);
15131501 }
1502+#endif
1503+ if (lpthread)
1504+ tcc_add_library_err(s1, "pthread");
1505+ tcc_add_library_err(s1, "c");
1506+#ifdef TCC_LIBGCC
1507+ if (!s1->static_link) {
1508+ if (TCC_LIBGCC[0] == '/')
1509+ tcc_add_file(s1, TCC_LIBGCC);
1510+ else
1511+ tcc_add_dll(s1, TCC_LIBGCC, 0);
1512+ }
1513+#endif
1514+#if defined TCC_TARGET_ARM && TARGETOS_FreeBSD
1515+ tcc_add_library_err(s1, "gcc_s"); // unwind code
15141516 #endif
15151517 if (TCC_LIBTCC1[0])
15161518 tcc_add_support(s1, TCC_LIBTCC1);
15171519
1518−#if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO
1519−#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
15201520 /* add crt end if not memory output */
15211521 if (s1->output_type != TCC_OUTPUT_MEMORY) {
1522+#if defined TCC_TARGET_MACHO
1523+ /* nothing to do */
1524+#elif TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
15221525 if (s1->output_type == TCC_OUTPUT_DLL)
15231526 tcc_add_crt(s1, "crtendS.o");
15241527 else
15251528 tcc_add_crt(s1, "crtend.o");
1526−#if TARGETOS_FreeBSD || TARGETOS_NetBSD
1529+# if !TARGETOS_OpenBSD
15271530 tcc_add_crt(s1, "crtn.o");
1528−#endif
1529− }
1530−#elif !defined(TCC_TARGET_MACHO)
1531− /* add crt end if not memory output */
1532− if (s1->output_type != TCC_OUTPUT_MEMORY)
1531+# endif
1532+#else
15331533 tcc_add_crt(s1, "crtn.o");
15341534 #endif
1535−#endif
1535+ }
15361536 }
15371537 }
15381538 #endif /* ndef TCC_TARGET_PE */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t