summaryrefslogtreecommitdiff
path: root/libc/misc/internals/__h_errno_location.c
AgeCommit message (Collapse)Author
2014-04-23LT.old: Make __errno_location/__h_errno_location thread safeVineet Gupta
WHY: errno in uClibc is not thread safe HOW: __errno_location and it's sibling __h_errno_location need to be called via PLT - even from within libc. That way when linked with pthread, intra-uClibc callers will also use the thread safe version. This is achieved by removing the GI alias for these functions, ensuring that they get called normally (via PLT) Verified with ARC LT.old and ARM cubieboard2 buildroot (LT.old) NPTL is unaffected by this bug. ------------ History behind this patch --------------------- This is a long standing bug (https://bugs.busybox.net/show_bug.cgi?id=2089) Others have tried to fix it in past (alteast Peter Korsgaard's patch in 2010), but somehow failed to be merged (or were backed out afterwards). http://lists.uclibc.org/pipermail/uclibc/2010-July/044176.html One of the causes could be side effect of atleast one more bug related to pthreads and static link which has now been fixed. http://lists.uclibc.org/pipermail/uclibc/2013-October/047958.html I have solved this w/o looking at other pacthes but would like to give credit to Peter and others for confirming that it makes sense. Cc: Christian Ruppert <christian.ruppert@abilis.com> CC: Francois Bedard <Francois.Bedard@synopsys.com> Cc: Joern Rennecke <joern.rennecke@embecosm.com> Cc: Jeremy Bennett <jeremy.bennett@embecosm.com> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Cc: Peter Korsgaard <peter@korsgaard.com> Cc: Khem Raj <raj.khem@gmail.com> Cc: buildroot@busybox.net Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-11-06Fix weak/strong attribute of __errno_location and it's __GI aliasVineet Gupta
A simple statically linked hello world program was segfaulting for ARC in linuxthreads.old configuration (although the root casue applies cross-arch for NPTL as well as linuxthreads.old as described) The crash was due to branch to NULL in _stdio_init 0001026c <_stdio_init>: 1026c: push_s blink 1026e: st.a r13,[sp,-8] 10272: bl.d 0 --> supposed call to __errno_location The call was NOT getting patched to libc internal only alias __GI___errno_location, because it was weak while it's exported cousin, __errno_location was strong/normal. arc-linux-uclibc-nm libc/misc/internals/__errno_location.os 00000000 W __GI___errno_location 00000000 T __errno_location This is exactly opposite to what is expected. Quoting Peter S. Mazinger, commit 87936cd013041 "errno and *_init cleanup" | The rule adopted: | for enabled threads we make in libc the __GI_x() variants strong, x() weak | and (should) provide another strong x() in libpthread. | If threads are disabled, even the __GI_x() variants are weak. With the fix, we see the right settings as below 00000000 T __GI___errno_location 00000000 W __errno_location Note that problem won't show up in a static busybox build as it references errno and that seems to elide the issue. I can confirm the same/more issues with latest ARM buildroot builds w/o my fix. (1). linuxthreads.old (broken just like ARC) arm-linux-nm uclibc-snapshot/libc/misc/internals/__errno_location.os 00000000 W __GI___errno_location 00000000 T __errno_location But presumably the issue there is NOT catestrophic because ARM linker is likely smarter and patches a NOP instead of NULL branch. 00008388 <_stdio_init>: 8388: e92d4038 push {r3, r4, r5, lr} 838c: e320f000 nop {0} (2) NPTL build (exported version is not weak) 00000000 T __GI___errno_location 00000000 T __errno_location This causes a static link with libpthread and test program referencing errno to fail to link. #include <errno.h> int main(void) { printf("%d\n", errno); } arm-linux-gcc -static -pthread -o tst tst.o arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libc.a(__errno_location.os): In function `__errno_location': __errno_location.c:(.text+0x0): multiple definition of `__errno_location' arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libpthread.a (errno_location.os):errno_location.c:(.text+0x0): first defined here Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Cc: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15errno, h_errno: correct them for non-TLSPeter S. Mazinger
Move h_errno related stuff to separate file. Do not hide errno and h_errno for non-TLS, else it keeps being 0. Make __[h_]errno_location weak for non-TLS. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15errno and *_init cleanupPeter S. Mazinger
Define a common view of __errno_location, __h_errno_location in common header and use that everywhere, __uClibc_main.c is no special. The rule adopted: for enabled threads we make in libc the __GI_x() variants strong, x() weak and (should) provide another strong x() in libpthread. If threads are disabled, even the __GI_x() variants are weak. _stdio_init,_stdio_term,_locale_init: make all hidden weak in common header Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2010-07-06Revert "don't make __errno_location / __h_errno_location hidden"Austin Foxley
This reverts commit 0d6ee549bc86fd330672a79d9a87d2c3825eea67. We need to find a solution that will work in shared and static libraries Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
2010-07-05don't make __errno_location / __h_errno_location hiddenPeter Korsgaard
Closes #2089 (https://bugs.busybox.net/show_bug.cgi?id=2089) __errno_location / __h_errno_location access has to go through the PLT like malloc/free, so the linuxthread variants gets used instead when compiling with -pthread. Based on http://github.com/mat-c/uClibc/commit/328d392c54aa5dc2b8e7f398a419087de497de2b Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
2009-09-18trim Experimentally off and uncommented hiddenBernhard Reutner-Fischer
sed -i -e '/Experimentally off - /d' $(grep -rl "Experimentally off - " *) sed -i -e '/^\/\*[[:space:]]*libc_hidden_proto(/d' $(grep -rl "libc_hidden_proto" *) should be a nop Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2008-11-20Last portion of libc_hidden_proto removal.Denis Vlasenko
Appears to build fine (several .configs tried)
2007-02-21redo errno handling so that it should work both in thread and non-threaded ↵Mike Frysinger
situations
2006-08-23sync with psm: update errno handling to be the same on all archesMike Frysinger
2006-02-02even the hidden version of the weaks in libc (as strong in libpthread) have ↵Peter S. Mazinger
to be weaks
2006-01-16Last relocs jump and global data, (even locales) that I could remove are ↵Peter S. Mazinger
gone from libc. The remaining are left as exercise for others ;-)
2006-01-16some global data relocs gonePeter S. Mazinger
2002-02-26Proper support for setting h_errnoEric Andersen