Hi tcc list -- I was looking to update the OpenBSD package of tcc. I saw that recently, a configure option for PIE binaries was added. This would be very desirable for us, so I tried to enable it only to find that all binaries produced with --config-pie were broken. This is because tcc incorrectly tries to use crtbeginS.o and crtendS.o when linking PIE binaries on OpenBSD. Those files should only be used when creating shared libraries.
This diff fixes things. With it, tcc links the correct files both for PIE binaries and shared libraries. This was tested against the in-base clang compiler that ships with OpenBSD. I plan to push this to mob unless there are concerns. I don't know if something similar needs to be done for FreeBSD or NetBSD. ~Brian diff --git a/libtcc.c b/libtcc.c index 4327a13..3102961 100644 --- a/libtcc.c +++ b/libtcc.c @@ -924,7 +924,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) #if TARGETOS_OpenBSD if (output_type != TCC_OUTPUT_DLL) tcc_add_crt(s, "crt0.o"); - if (output_type & TCC_OUTPUT_DYN) + if (output_type == TCC_OUTPUT_DLL) tcc_add_crt(s, "crtbeginS.o"); else tcc_add_crt(s, "crtbegin.o"); diff --git a/tccelf.c b/tccelf.c index 1103f3d..c340b3e 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1518,11 +1518,16 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) if (s1->output_type != TCC_OUTPUT_MEMORY) { #if defined TCC_TARGET_MACHO /* nothing to do */ -#elif TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD +#elif TARGETOS_FreeBSD || TARGETOS_NetBSD if (s1->output_type & TCC_OUTPUT_DYN) tcc_add_crt(s1, "crtendS.o"); else tcc_add_crt(s1, "crtend.o"); +#elif TARGETOS_OpenBSD + if (s1->output_type == TCC_OUTPUT_DLL) + tcc_add_crt(s1, "crtendS.o"); + else + tcc_add_crt(s1, "crtend.o"); # if !TARGETOS_OpenBSD tcc_add_crt(s1, "crtn.o"); # endif _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel