aboutsummaryrefslogtreecommitdiff
path: root/src (follow)
Commit message (Expand)AuthorAgeFilesLines
* add locale framework•••this commit adds non-stub implementations of setlocale, duplocale, newlocale, and uselocale, along with the data structures and minimal code needed for representing the active locale on a per-thread basis and optimizing the common case where thread-local locale settings are not in use. at this point, the data structures only contain what is necessary to represent LC_CTYPE (a single flag) and LC_MESSAGES (a name for use in finding message translation files). representation for the other categories will be added later; the expectation is that a single pointer will suffice for each. for LC_CTYPE, the strings "C" and "POSIX" are treated as special; any other string is accepted and treated as "C.UTF-8". for other categories, any string is accepted after being truncated to a maximum supported length (currently 15 bytes). for LC_MESSAGES, the name is kept regardless of whether libc itself can use such a message translation locale, since applications using catgets or gettext should be able to use message locales libc is not aware of. for other categories, names which are not successfully loaded as locales (which, at present, means all names) are treated as aliases for "C". setlocale never fails. locale settings are not yet used anywhere, so this commit should have no visible effects except for the contents of the string returned by setlocale. Rich Felker2014-07-029-22/+186
* fix failure of wide printf/scanf functions to set wide orientation•••in some cases, these functions internally call a byte-based input or output function before calling getwc/putwc, so they cannot rely on the latter to set the orientation. Rich Felker2014-07-022-0/+3
* fix typo in a comment in __libc_start_mainRich Felker2014-07-011-1/+1
* fix incorrect return value for fwide function•••when the orientation of the stream was already set, fwide was incorrectly returning its argument (the requested orientation) rather than the actual orientation of the stream. Rich Felker2014-07-011-1/+2
* fix ungrammatical comment in posix_spawn codeRich Felker2014-07-011-3/+3
* fix aliasing violations in mbtowc and mbrtowc•••these functions were setting wc to point to wchar_t aliasing itself as a "cheap" way to support null wc arguments. doing so was anything but cheap, since even without the aliasing violation, it would limit the compiler's ability to optimize. making wc point to a dummy object is equally easy and does not suffer from the above problems. Rich Felker2014-07-012-2/+4
* fix regression in mips dynamic linker•••this issue caused the address of functions in shared libraries to resolve to their PLT thunks in the main program rather than their correct addresses. it was observed causing crashes, though the mechanism of the crash was not thoroughly investigated. since the issue is very subtle, it calls for some explanation: on all well-behaved archs, GOT entries that belong to the PLT use a special relocation type, typically called JMP_SLOT, so that the dynamic linker can avoid having the jump destinations for the PLT resolve to PLT thunks themselves (they also provide a definition for the symbol, which must be used whenever the address of the function is taken so that all DSOs see the same address). however, the traditional mips PIC ABI lacked such a JMP_SLOT relocation type, presumably because, due to the way PIC works, the address of the PLT thunk was never needed and could always be ignored. prior to commit adf94c19666e687a728bbf398f9a88ea4ea19996, the mips version of reloc.h contained a hack that caused all symbol lookups to be treated like JMP_SLOT, inhibiting undefined symbols from ever being used to resolve symbolic relocations. this hack goes all the way back to commit babf820180368f00742ec65b2050a82380d7c542, when the mips dynamic linker was first made usable. during the recent refactoring to eliminate arch-specific relocation processing (commit adf94c19666e687a728bbf398f9a88ea4ea19996), this hack was overlooked and no equivalent functionality was provided in the new code. fixing the problem is not as simple as adding back an equivalent hack, since there is now also a "non-PIC ABI" that can be used for the main executable, which actually does use a PLT. the closest thing to official documentation I could find for this ABI is nonpic.txt, attached to Message-ID: 20080701202236.GA1534@caradoc.them.org, which can be found in the gcc mailing list archives and elsewhere. per this document, undefined symbols corresponding to PLT thunks have the STO_MIPS_PLT bit set in the symbol's st_other field. thus, I have added an arch-specific rule for mips, applied at the find_sym level rather than the relocation level, to reject undefined symbols with the STO_MIPS_PLT bit clear. the previous hack of treating all mips relocations as JMP_SLOT-like, rather than rejecting the unwanted symbols in find_sym, probably also caused dlsym to wrongly return PLT thunks in place of the correct address of a function under at least some conditions. this should now be fixed, at least for global-scope symbol lookups. Rich Felker2014-06-301-1/+6
* fix regression in dynamic linker error reporting•••due to a mistake when refactoring the error printing for the dynamic linker (commit 7c73cacd09a51a87484db5689864743e4984a84d), all messages were suppressed and replaced by blank lines. Rich Felker2014-06-291-9/+5
* add routing protocols to getprotoent-family functions•••iptables and quagga need them to work. Timo Teräs2014-06-241-0/+2
* rename dynamic linker _start to _dlstart in the stub version•••the renaming was previously applied to all real versions of the function in commit 3fa2eb2aba8d6b54dec53e7ad4c37e17392b166f. Rich Felker2014-06-231-1/+1
* add __sysv_signal abi-compat alias for the signal function•••it should be noted that the "real" __sysv_signal, which we do not implement, is semantically different from signal. references to __sysv_signal arise in code built against glibc under certain combinations of feature test macros, and are almost surely unintentional since the legacy sysv signal behavior has fundamental race conditions that cannot be worked around and which make it impossible to use safely. Rich Felker2014-06-221-0/+1
* add __xmknod and __xmknodat abi-compat functions•••these are put alongside the similar functions for __xstat, etc. in __xstat.c to avoid bloating the number of source files. Rich Felker2014-06-221-0/+10
* consolidate __xstat abi-compat functions into a single source file•••these are mostly intended for use with dynamic linking (although they can also be used statically with object files compiled against glibc headers), so having them broken down into separate source files to optimize for static linking is unlikely to be worth the cost having more files in the source tree (which contributes to libc.a overhead, compile time, link time, ar/linker command line size exhaustion, and so on). Rich Felker2014-06-224-27/+18
* implement fmtmsg function•••contributed by Isaac Dunham. this seems to be the last interface that was missing for complete POSIX 2008 base + XSI coverage. Rich Felker2014-06-211-0/+90
* implement result address sorting in the resolver (getaddrinfo, etc.)Rich Felker2014-06-212-0/+136
* fix gethostby*_r result pointer value on error•••according to the documentation in the man pages, the GNU extension functions gethostbyaddr_r, gethostbyname_r and gethostbyname2_r are guaranteed to set the result pointer to NULL in case of error or no result. Timo Teräs2014-06-202-0/+3
* fix sendmmsg emulation return value for zero-length vector•••this case is not even documented, but the kernel returns 0 here and it makes sense to be consistent. Rich Felker2014-06-201-0/+1
* rename dynamic linker entry point from _start to _dlstart•••the main motivation for this change is to aid in debugging. since the main program's entry point is also named _start, it was difficult to set breakpoints or quickly identify which _start execution stopped in. Rich Felker2014-06-208-19/+19
* implement sendmmsg and recvmmsg•••these are not pure syscall wrappers because they have to work around kernel API bugs on 64-bit archs. the workarounds could probably be made somewhat more efficient, but at the cost of more complexity. this may be revisited later. Rich Felker2014-06-192-0/+44
* add tlsdesc support for x86_64Rich Felker2014-06-191-0/+40
* separate __tls_get_addr implementation from dynamic linker/init_tls•••such separation serves multiple purposes: - by having the common path for __tls_get_addr alone in its own function with a tail call to the slow case, code generation is greatly improved. - by having __tls_get_addr in it own file, it can be replaced on a per-arch basis as needed, for optimization or ABI-specific purposes. - by removing __tls_get_addr from __init_tls.c, a few bytes of code are shaved off of static binaries (which are unlikely to use this function unless the linker messed up). Rich Felker2014-06-193-11/+23
* add tlsdesc support for i386Rich Felker2014-06-191-0/+27
* optimize i386 ___tls_get_addr asmRich Felker2014-06-191-1/+8
* change dynamic TLS installation strategy to optimize access•••previously, accesses to dynamic TLS had to check two conditions before being able to use a dtv slot: (1) that the module index was within the bounds of the current dtv size, and (2) that the dynamic tls for the requested module index was already installed in the dtv. this commit changes the installation strategy so that, whenever an attempt is made to access dynamic TLS that's not yet installed in the dtv, the dynamic TLS for all lower-index modules is also installed. thus it provides a new invariant: if a given module index is within the bounds of the current dtv size, we automatically know that its TLS is installed and directly available. the requirement that the second condition (above) be checked is eliminated. Rich Felker2014-06-191-8/+14
* add arch-generic support for tlsdesc relocations to dynamic linker•••this code is non-functional without further changes to link up the arch-specific reloc types for tlsdesc and add asm implementations of __tlsdesc_static and __tlsdesc_dynamic. Rich Felker2014-06-192-0/+54
* fix incorrect comparison loop condition in memmem•••the logic for this loop was copied from null-terminated-string logic in strstr without properly adapting it to work with explicit lengths. presumably this error could result in false negatives (wrongly comparing past the end of the needle/haystack), false positives (stopping comparison early when the needle contains null bytes), and crashes (from runaway reads past the end of mapped memory). Rich Felker2014-06-191-2/+2
* reduce code duplication in dynamic linker error paths•••eventually this should help making dlerror thread-safe too. Rich Felker2014-06-181-16/+16
* refactor to remove arch-specific relocation code from dynamic linker•••this was one of the main instances of ugly code duplication: all archs use basically the same types of relocations, but roughly equivalent logic was duplicated for each arch to account for the different naming and numbering of relocation types and variation in whether REL or RELA records are used. as an added bonus, both REL and RELA are now supported on all archs, regardless of which is used by the standard toolchain. Rich Felker2014-06-181-8/+89
* fix missing argument to syscall in fanotify_markClément Vasseur2014-06-141-1/+1
* support optional-argument extension to getopt via double-colon•••this extension is not incompatible with the standard behavior of the function, not expensive, and avoids requiring a replacement getopt with full GNU extensions for a few important apps including busybox's sed with the -i option. Rich Felker2014-06-111-2/+5
* simplify errno implementation•••the motivation for the errno_ptr field in the thread structure, which this commit removes, was to allow the main thread's errno to keep its address when lazy thread pointer initialization was used. &errno was evaluated prior to setting up the thread pointer and stored in errno_ptr for the main thread; subsequently created threads would have errno_ptr pointing to their own errno_val in the thread structure. since lazy initialization was removed, there is no need for this extra level of indirection; __errno_location can simply return the address of the thread's errno_val directly. this does cause &errno to change, but the change happens before entry to application code, and thus is not observable. Rich Felker2014-06-104-4/+2
* replace all remaining internal uses of pthread_self with __pthread_self•••prior to version 1.1.0, the difference between pthread_self (the public function) and __pthread_self (the internal macro or inline function) was that the former would lazily initialize the thread pointer if it was not already initialized, whereas the latter would crash in this case. since lazy initialization is no longer supported, use of pthread_self no longer makes sense; it simply generates larger, slower code. Rich Felker2014-06-1011-12/+12
* add thread-pointer support for pre-2.6 kernels on i386•••such kernels cannot support threads, but the thread pointer is also important for other purposes, most notably stack protector. without a valid thread pointer, all code compiled with stack protector will crash. the same applies to any use of thread-local storage by applications or libraries. the concept of this patch is to fall back to using the modify_ldt syscall, which has been around since linux 1.0, to setup the gs segment register. since the kernel does not have a way to automatically assign ldt entries, use of slot zero is hard-coded. if this fallback path is used, __set_thread_area returns a positive value (rather than the usual zero for success, or negative for error) indicating to the caller that the thread pointer was successfully set, but only for the main thread, and that thread creation will not work properly. the code in __init_tp has been changed accordingly to record this result for later use by pthread_create. Rich Felker2014-06-102-13/+22
* avoid spurious lookup failures from badly-behaved nameservers•••the results of a dns query, whether it's performed as part of one of the standard name-resolving functions or directly by res_send, should be a function of the query, not of the particular nameserver that responds to it. thus, all responses which indicate a failure or refusal by the nameserver, as opposed to a positive or negative result for the query, should be ignored. the strategy used is to re-issue the query immediately (but with a limit on the number of retries, in case the server is really broken) when a response code of 2 (server failure, typically transient) is seen, and otherwise take no action on bad responses (which generally indicate a misconfigured nameserver or one which the client does not have permission to use), allowing the normal retry interval to apply and of course accepting responses from other nameservers queried in parallel. empirically this matches the traditional resolver behavior for nameservers that respond with a code of 2 in the case where there is just a single nameserver configured. the behavior diverges when multiple nameservers are available, since musl is querying them in parallel. in this case we are mildly more aggressive at retrying. Rich Felker2014-06-071-5/+22
* use default timezone from /etc/localtime if $TZ is unset/blank•••the way this is implemented, it also allows explicit setting of TZ=/etc/localtime even for suid programs. this is not a problem because /etc/localtime is a trusted path, much like the trusted zoneinfo search path. Rich Felker2014-06-061-2/+3
* implement %y and %C specifiers in strptimeTimo Teräs2014-06-061-4/+10
* avoid invalid use of va_arg in open•••reading the variadic mode argument is only valid when the O_CREAT flag is present. this probably does not matter, but is needed for formal correctness, and could affect LTO or other full-program analysis. Rich Felker2014-06-061-5/+8
* add O_CLOEXEC fallback for open and related functions•••since there is no easy way to detect whether open honored or ignored the O_CLOEXEC flag, the optimal solution to providing a fallback is simply to make the fcntl syscall to set the close-on-exec flag immediately after open returns. Rich Felker2014-06-063-1/+9
* optimize SOCK_CLOEXEC fallback for socket function•••the fcntl function is heavy, so make the syscall directly instead. also, avoid the code size and runtime overhead of querying the old flags, since it's reasonable to assume nothing will be set on a newly-created socket. this code is only used on old kernels which lack proper atomic close-on-exec support, so future changes that might invalidate such an assumption do not need to be considered. Rich Felker2014-06-061-2/+2
* add SOCK_CLOEXEC fallback for socketpair on old kernels•••as usual, this is non-atomic, but better than producing an error or failing to set the close-on-exec flag at all. Rich Felker2014-06-061-1/+19
* implement dn_comp RFC 1035 domain name compression•••the input name is validated, the other parameters are assumed to be valid (the list of already compressed names are not checked for infinite reference loops or out-of-bound offsets). names are handled case-sensitively for now. Szabolcs Nagy2014-06-061-1/+102
* accept trailing . and empty domain names•••trailing . should be accepted in domain name strings by convention (RFC 1034), host name lookup accepts "." but rejects empty "", res_* interfaces also accept empty name following existing practice. Szabolcs Nagy2014-06-063-12/+16
* fix fd leak in tmpfile when the fdopen operation fails•••this condition could only happen due to malloc failure. the fdopen operation is also moved to take place after the unlink to minimize the window during which a link to the file exists in the directory table. Rich Felker2014-06-061-1/+2
* fix the domain name length limit checks•••A domain name is at most 255 bytes long (RFC 1035), but the string representation is two bytes smaller so the strlen maximum is 253. Szabolcs Nagy2014-06-053-8/+8
* fix multiple validation issues in dns response label parsing•••Due to an error introduced in commit fcc522c92335783293ac19df318415cd97fbf66b, checking of the remaining output buffer space was not performed correctly, allowing malformed input to write past the end of the buffer. In addition, the loop detection logic failed to account for the possibility of infinite loops with no output, which would hang the function. The output size is now limited more strictly so only names with valid length are accepted. Szabolcs Nagy2014-06-051-4/+6
* fix missing function declarations in refactored ip literal parsing codeRich Felker2014-06-051-0/+1
* add support for reverse port lookups from services file to getnameinfo•••this also affects the legacy getservbyport family, which uses getnameinfo as its backend. Rich Felker2014-06-041-4/+35
* add support for reverse name lookups from hosts file to getnameinfo•••this also affects the legacy gethostbyaddr family, which uses getnameinfo as its backend. some other minor changes associated with the refactoring of source files are also made; in particular, the resolv.conf parser now uses the same code that's used elsewhere to handle ip literals, so as a side effect it can now accept a scope id for nameserver addressed with link-local scope. Rich Felker2014-06-045-50/+122
* remove some dummy "ent" function aliases that duplicated real ones•••the service and protocol functions are defined also in other files, and the protocol ones are actually non-nops elsewhere, so the weak definitions in ent.c could have prevented the strong definitions from getting pulled in and used in some static programs. Rich Felker2014-06-041-8/+0
* simplify vasprintf implementation•••the old implementation preallocated a buffer in order to try to avoid calling vsnprintf more than once. not only did this potentially lead to memory fragmentation from trimming with realloc; it also pulled in realloc/free, which otherwise might not be needed in a static linked program. Rich Felker2014-06-041-14/+1