summaryrefslogtreecommitdiff
path: root/Makefile
AgeCommit message (Collapse)AuthorLines
2017-03-21increase limit on locale name length from 15 to 23 bytesRich Felker-1/+1
the old limit was one byte too short to support locale names of the form xx_XX.UTF-8@modifier where modifier is more than 3 bytes, a form which various real-world locale names take. the problem could be avoided by omitting the useless ".UTF-8" part, but users may need to have it present when operating on mixed-libc systems or when it will be carried over (e.g. across ssh) to other systems. the new limit is chosen sufficient for existing/reasonable locale names while still keeping the size of setlocale's static buffer small. also add locale_impl.h to the Makefile's list of headers which force rebuild of source files, to prevent dangerously inconsistent object files from getting used after this change.
2016-05-12deduplicate __NR_* and SYS_* syscall number definitionsBobby Bingham-1/+5
2016-02-19generate list of crt files to install instead of hard-coding in makefileRich Felker-1/+1
this follows the principle of having the source tree layout define build semantics. it also makes it possible for crt/$(ARCH) to define additional installable files, which may be needed for midipix and other future targets.
2016-02-17support clean/distclean make targets in unconfigured treeRich Felker-10/+16
commit 2f853dd6b9a95d5b13ee8f9df762125e0588df5d moved the error handling for $(ARCH) not being set such that it applied to all targets, including clean and distclean. previously these targets worked even in an unconfigured tree. to restore the old behavior, make most of the makefile body conditional on $(ARCH) being set/non-empty and produce the error via a fake "all" target in the conditional branch for the case where $(ARCH) is empty.
2016-02-17adjust makefile to make crt/ and ldso/ sources arch-replaceableRich Felker-15/+18
prior to commit 2f853dd6b9a95d5b13ee8f9df762125e0588df5d which overhauled the makefile for out-of-tree builds, crt/*.c files were replaceable by crt/$(ARCH)/*.s, and top-level ldso/ did not exist (its files were under src/ldso). since then, crti.o and crtn.o have been hard-coded as arch-specific, but none of the other files in crt/ or ldso/ were replaceable at all. in preparation for easy integration with midipix, which has a port of musl to windows, it needs to be possible to override the ELF-specific code in these files. making the same arch-replacements system work throughout the whole source tree also improves consistency and removes the need for some file-specific rules (crti.o and crtn.o) in the makefile.
2016-01-31don't suppress shared libc when linker lacks -Bsymbolic-functionsRich Felker-2/+1
previous work overhauling the dynamic linker made it so that linking libc with -Bsymbolic-functions was no longer mandatory, but the configure logic that forced --disable-shared when ld failed to accept the option was left in place. this commit removes the hard-coded -Bsymbolic-functions from the Makefile and changes the configure test to one that simply adds it to the auto-detected LDFLAGS on success.
2016-01-27add arch/generic include fallback to build rulesRich Felker-2/+6
this sets the stage for the first phase of the bits deduplication. bits headers which are identical for "most" archs will be moved to arch/generic/bits.
2016-01-25add ssp suppression to some arch-override files that may need itRich Felker-2/+4
these were not covered by the parent-level rules with the new build system. in the old build system, the equivalent files were often in arch/$(ARCH)/src and likewise lacked the suppression. this could lead to early crashing (before thread pointer init) when libc itself was built with stack protector enabled.
2016-01-25use same object files for libc.a and libc.so if compiler produces PICRich Felker-2/+3
now that .lo and .o files differ only by whether -fPIC is passed (and no longer at the source level based on the SHARED macro), it's possible to use the same object files for both static and shared libc when the compiler would produce PIC for the static files anyway. this happens if the user has included -fPIC in their CFLAGS or if the compiler has been configured to produce PIE by default. we use the .lo files for both, and still append -fPIC to the CFLAGS, rather than using the .o files so that libc.so does not break catastrophically if the user later removes -fPIC from CFLAGS in config.mak or on the make command line. this also ensures that we get full -fPIC in case -fpic, -fPIE, or some other lesser-PIC option was passed in CFLAGS.
2016-01-25move dynamic linker to its own top-level directory, ldsoRich Felker-8/+10
this eliminates the last need for the SHARED macro to control how files in the src tree are compiled. the same code is used for both libc.a and libc.so, with additional code for the dynamic linker (from the new ldso tree) being added to libc.so but not libc.a. separate .o and .lo object files still exist for the src tree, but the only difference is that the .lo files are built as PIC. in the future, if/when we add dlopen support for static-linked programs, much of the code in dynlink.c may be moved back into the src tree, but properly factored into separate source files. in that case, the code in the ldso tree will be reduced to just the dynamic linker entry point, self-relocation, and loading of libraries needed by the main application.
2016-01-22remove arch/$(ARCH)/src from the build systemRich Felker-1/+1
the files that used to come from extra src dirs under the arch dir have all been removed or moved to appropriate places under the main src tree.
2016-01-20simplify "make clean" and remove unneeded lib dir from treeRich Felker-7/+1
the lib dir is automatically created if needed by the out-of-tree build logic, and now that all generated files are in obj and lib, deleting them is much simpler. using "rm -rf" is also more thorough, as it picks up object files that were left around from source files that no longer exist or which are no longer to be used because an arch-specific replacement file was added or removed.
2016-01-20deduplicate compiler invocation command line in makefileRich Felker-7/+9
also clean up duplication of CFLAGS passing to assembler.
2016-01-20remove outdated/incorrect comment about AS_CMD from makefileRich Felker-1/+0
2016-01-20remove support for subarch .sub files from the makefileRich Felker-16/+2
as of commit af21a82ccc8687aa16e85def7db95efeae4cf72e, .sub files are no longer in use. removing the makefile machinery to handle them not only cleans up and simplifies the makefile, but also significantly reduces make's startup time.
2016-01-20fix build regression for arm pre-v7 from out-of-tree build patchRich Felker-1/+1
commit 2f853dd6b9a95d5b13ee8f9df762125e0588df5d failed to replicate the old makefile logic that caused arch/arm/src/arm/atomics.s to be built. since this was the only .s file under arch/*/src, rather than trying to reproduce the old logic, I'm just moving it up a level and adjusting the glob pattern in the makefile to catch it. eventually arch/*/src will probably be removed in favor of moving all these files to appropriate src/*/$(ARCH) locations.
2016-01-19eliminate separate static/shared CFLAGS vars in makefileRich Felker-13/+13
this allows the rules for .o and .lo files to be identical, with -fPIC and -DSHARED added for .lo files via target-specific variable append. this is arguably cleaner now and will allow more cleanup and removal of redundant rule bodies after other prerequisite changes are made.
2016-01-19add support for arch-provided replacement files as .c or .SRich Felker-3/+9
previously, replacement files provided in $(ARCH) dirs under src/ had to be .s files. in order to replace a file with C source, an empty .s file was needed there to suppress the original file, and a separate .c file was needed in arch/$(ARCH)/src/. support for .S is new and is aimed at short-term use eliminating .sub files. asm source files are still expected not to make any heavy preprocessor use, just simple conditionals on subarch. eventually most affected files may be replaced with C source files with minimal inline asm instead of asm source files.
2016-01-17support out-of-tree buildPetr Hosek-51/+75
this change adds support for building musl outside of the source tree. the implementation is similar to autotools where running configure in a different directory creates config.mak in the current working directory and symlinks the makefile, which contains the logic for creating all necessary directories and resolving paths relative to the source directory. to support both in-tree and out-of-tree builds with implicit make rules, all object files are now placed into a separate directory.
2015-11-18fix build regression from removal of #ifdef SHAREDRich Felker-1/+1
2015-11-02keep user-provided CFLAGS/LDFLAGS separate from those added by configureRich Felker-4/+8
this way, overriding these variables on the make command line (or just re-passing the originally-passed values when invoking make) won't suppress use of the flags added by configure.
2015-10-22fix breakage when user overrides CFLAGS on the make command lineRich Felker-4/+4
these per-target CFLAGS adjustments are mandatory additions to the command line for building the affected targets, not part of the user-provided CFLAGS for tuning. my intent was always that the variable append operations would take place after user settings, but when a variable is set on the command line, it overrides all definitions in the makefile, including target-specific ones. based on patch by Szabolcs Nagy.
2015-10-08factor common awk functions for CFI generation scripts into new fileAlex Dowad-1/+1
There is a lot which could be common between i386 and x86_64, but none of it will be useful for any other arch. These should be useful for all archs, however.
2015-08-30remove use of buggy .SECONDARY special target in makefileRich Felker-2/+0
this functionality is affected by GNU make bug #30653, "intermediate files incorrectly pruned in parallel builds". on affected versions of make, parallel builds attempt to compile source files before alltypes.h is generated. as noted with commit a91ebdcfac6804714a1fe39f4375e2b4ebab085b, which added the use of .SECONDARY, suppression of removal of "intermediate" files does not seem to be needed at present. if it is needed in the future, it should be achievable by explicitly mentioning their names as targets or prerequisites.
2015-08-27fix makefile suppression of intermediate file removalRich Felker-1/+1
at one point, GNU make was removing crt/*.o after producing the copies in lib/ due to an arcane misfeature for handling "intermediate" files. the circumstances that caused this are no longer present in our makefile, but the previous workaround using .PRECIOUS was wrong and could result in corrupt/partial files being left behind during an interrupted build. using .SECONDARY is the correct, documented fix that will prevent deletion of "intermediate" files from ever resurfacing.
2015-08-26Build process uses script to add CFI directives to x86 asmAlex Dowad-2/+10
Some functions implemented in asm need to use EBP for purposes other than acting as a frame pointer. (Notably, it is used for the 6th argument to syscalls with 6 arguments.) Without frame pointers, GDB can only show backtraces if it gets CFI information from a .debug_frame or .eh_frame ELF section. Rather than littering our asm with ugly .cfi directives, use an awk script to insert them in the right places during the build process, so GDB can keep track of where the current stack frame is relative to the stack pointer. This means GDB can produce beautiful stack traces at any given point when single-stepping through asm functions. Additionally, when registers are saved on the stack and later overwritten, emit ..cfi directives so GDB will know where they were saved relative to the stack pointer. This way, when you look back up the stack from within an asm function, you can still reliably print the values of local variables in the caller. If this awk script were to understand every possible wild and crazy contortion that an asm programmer can do with the stack and registers, and always emit the exact ..cfi directives needed for GDB to know what the register values were in the preceding stack frame, it would necessarily be as complex as a full x86 emulator. That way lies madness. Hence, we assume that the stack pointer will _only_ ever be adjusted using push/pop or else add/sub with a constant. We do not attempt to detect every possible way that a register value could be saved for later use, just the simple and common ways. Thanks to Szabolcs Nagy for suggesting numerous improvements to this code.
2015-07-06add musl-clang, a wrapper for system clang installsShiz-0/+5
musl-clang allows the user to compile musl-powered programs using their already existent clang install, without the need of a special cross compiler. it achieves this by wrapping around both the system clang install and the linker and passing them special flags to re-target musl at runtime. it does only affect invocations done through the special musl-clang wrapper script, so that the user setup remains fully intact otherwise. the clang wrapper consists of the compiler frontend wrapper script, musl-clang, and the linker wrapper script, ld.musl-clang. musl-clang makes sure clang invokes ld.musl-clang to link objects; neither script needs to be in PATH for the wrapper to work.
2015-07-06build: overhaul wrapper script system for multiple wrapper supportShiz-1/+3
this overhauls part of the build system in order to support multiple toolchain wrapper scripts, as opposed to solely the musl-gcc wrapper as before. it thereby replaces --enable-gcc-wrapper with --enable-wrapper=..., which has the options 'auto' (the default, detect whether to use wrappers), 'all' (build and install all wrappers), 'no' (don't build any) and finally the options named after the individual compiler scripts (currently only 'gcc' is available) to build and install only that wrapper. the old --enable-gcc-wrapper is removed from --help, but still available. it also modifies the wrappers to use the C compiler specified to the build system as 'inner' compiler, when applicable. as wrapper detection works by probing this compiler, it may not work with any other.
2015-06-03add additional Makefile dependency rules for rcrt1.o PIE start fileRich Felker-2/+4
2015-05-26add rcrt1 start file for fully static-linked PIERich Felker-2/+2
static-linked PIE files need startup code to relocate themselves, much like the dynamic linker does. rcrt1.c reuses the code in dlstart.c, stage 1 of the dynamic linker, which in turn reuses crt_arch.h, to achieve static PIE with no new code. only relative relocations are supported. existing toolchains that don't yet support static PIE directly can be repurposed by passing "-shared -Wl,-Bstatic -Wl,-Bsymbolic" instead of "-static -pie" and substituting rcrt1.o in place of crt1.o. all libraries being linked must be built as PIC/PIE; TEXTRELs are not supported at this time.
2015-05-26fix incorrect application of visibility to Scrt1.oRich Felker-1/+1
commit de2b67f8d41e08caa56bf6540277f6561edb647f attempted to avoid having vis.h affect crt files, but the Makefile variable used, CRT_LIBS, refers to the final output copies in the lib directory, not the copies in the crt build directory, and thus the -DCRT was not applied. while unlikely to be noticed, this regression probably broke production of PIE executables whose main functions are not in the executable but rather a shared library.
2015-04-23add dependency of dlstart.lo on crt_arch.h to MakefileRich Felker-1/+1
2015-04-19add optional global visibility overrideRich Felker-0/+2
this is implemented via the build system and does not affect source files. the idea is to use protected or hidden visibility to prevent the compiler from pessimizing function calls within a shared (or position-independent static) libc in the form of overhead setting up for a call through the PLT. the ld-time symbol binding via the -Bsymbolic-functions option already optimized out the PLT itself, but not the code in the caller needed to support a call through the PLT. on some archs this overhead can be substantial; on others it's trivial.
2015-04-13allow libc itself to be built with stack protector enabledRich Felker-0/+7
this was already essentially possible as a result of the previous commits changing the dynamic linker/thread pointer bootstrap process. this commit mainly adds build system infrastructure: configure no longer attempts to disable stack protector. instead it simply determines how so the makefile can disable stack protector for a few translation units used during early startup. stack protector is also disabled for memcpy and memset since compilers (incorrectly) generate calls to them on some archs to implement struct initialization and assignment, and such calls may creep into early initialization. no explicit attempt to enable stack protector is made by configure at this time; any stack protector option supported by the compiler can be passed to configure in CFLAGS, and if the compiler uses stack protector by default, this default is respected.
2015-04-13dynamic linker bootstrap overhaulRich Felker-1/+1
this overhaul further reduces the amount of arch-specific code needed by the dynamic linker and removes a number of assumptions, including: - that symbolic function references inside libc are bound at link time via the linker option -Bsymbolic-functions. - that libc functions used by the dynamic linker do not require access to data symbols. - that static/internal function calls and data accesses can be made without performing any relocations, or that arch-specific startup code handled any such relocations needed. removing these assumptions paves the way for allowing libc.so itself to be built with stack protector (among other things), and is achieved by a three-stage bootstrap process: 1. relative relocations are processed with a flat function. 2. symbolic relocations are processed with no external calls/data. 3. main program and dependency libs are processed with a fully-functional libc/ldso. reduction in arch-specific code is achived through the following: - crt_arch.h, used for generating crt1.o, now provides the entry point for the dynamic linker too. - asm is no longer responsible for skipping the beginning of argv[] when ldso is invoked as a command. - the functionality previously provided by __reloc_self for heavily GOT-dependent RISC archs is now the arch-agnostic stage-1. - arch-specific relocation type codes are mapped directly as macros rather than via an inline translation function/switch statement.
2014-06-25add tarball-producing targets to Makefile for ease of releaseRich Felker-0/+4
my old, out-of-tree release script that performed a clone rather than using git archive checked the VERSION file to make sure that it matched before doing a release. I believe there should be a way to do the same with git commands (without resorting to checking out the desired tag) but I have not yet found a way, so care should be taken when using these targets that the correctness of the VERSION file is not overlooked.
2014-06-20rename dynamic linker entry point from _start to _dlstartRich Felker-1/+1
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.
2013-12-04remove dependency of version.h on .git/* to avoid errorsRich Felker-1/+1
the wildcard function in GNU make includes dangling symlinks; if any exist under the .git directory, they would get added as dependencies, causing make to exit with an error due to lacking a rule to build the missing file. as far as I can tell, git operations which should force version.h to be rebuilt must all touch the mtime of the top-level .git directory.
2013-12-01add infrastructure to record and report the version of libc.soRich Felker-1/+7
this is still experimental and subject to change. for git checkouts, an attempt is made to record the exact revision to aid in bug reports and debugging. no version information is recorded in the static libc.a or binaries it's linked into.
2013-08-31fix regression in creation of ldso symlinkRich Felker-1/+1
DESTDIR was wrongly included in the symlink contents.
2013-08-18re-add logic for ignoring failure of ld.so symlink installationRich Felker-1/+1
this was inadvertently removed when switching to the new install.sh.
2013-08-17replace system's install command with a shell scriptRich Felker-7/+7
the historical (non-standardized) install command is really inappropriate for installing binaries/libraries on a system that utilizes memory-mapped executable files. rather than replacing an existing file atomically, it overwrites the existing file. this can cause running programs to see a partially-modified version of the file, resulting in unpredictable behavior, or SIGBUS. a MAP_COPY mode for mmap would get around this problem, but Linux lacks MAP_COPY. the shell script added with this commit works around the problem by writing temporary files and moving them into place. unlike the historical install utility, it also support a -l option for installing a symbolic link atomically, via the same method.
2013-08-16fix atomicity and other issues installing dynamic linker symlinkRich Felker-5/+3
ln -sf is non-atomic; it unlinks the destination first. instead, make a temporary link and rename it into place. this commit also fixes some of the dependency tracking behavior for the link. depending on the directory it's to be installed in is not reasonable; it causes a new link to be attempted if the library directory has been modified, but does not attempt to make a new link just because libc has been updated. instead, depend on the target to be linked to. this will ensure that, if prefix has changed but syslibdir has not, the link will be updated to point to the new prefix.
2013-08-14rework makefile subarch logic to allow shared filesRich Felker-4/+12
instead of subarchs getting their own .s files which are used directly by the makefile to replace the .c file, they now must provide a .sub file whose contents are a pathname, relative to the location of the .sub file, which will substitute for the .c file. essentially these files are acting as symbolic links, but implemented as text files.
2013-08-11add subarch asm support for PIC objects/shared libcRich Felker-0/+3
this rule was omitted in previous subarch asm commit
2013-08-11allow subarch-specific asm, including asm specific to the defaultRich Felker-0/+3
the default subarch is the one whose full name is just the base arch name, with no suffixes. normally, either the asm in the default subarch is suitable for all subarch variants, or separate asm is mandatory for each variant. however, in the case of asm which is purely for optimization purposes, it's possible to have asm that only works (or only performs well) on the default subarch, and not any othe the other variants. thus, I have added a mechanism to give a name to the default variant, for example "armel" for the default, little-endian arm. further such default-subarch names can be added in the future as needed.
2013-08-01work around gcc 4.8's generation of self-referential mem* functions at -O3Rich Felker-0/+3
2013-07-26new mostly-C crt1 implementationRich Felker-0/+4
the only immediate effect of this commit is enabling PIE support on some archs that did not previously have any Scrt1.s, since the existing asm files for crt1 override this C code. so some of the crt_arch.h files committed are only there for the sake of documenting what their archs "would do" if they used the new C-based crt1. the expectation is that new archs should use this new system rather than using heavy asm for crt1. aside from being easier and less error-prone, it also ensures that PIE support is available immediately (since Scrt1.o is generated from the same C source, using -fPIC) rather than having to be added as an afterthought in the porting process.
2013-07-22enhance build process to allow selective -O3 optimizationRich Felker-0/+3
the motivation for this patch is that the vast majority of libc is code that does not benefit at all from optimizations, but that certain components like string/memory operations can be major performance bottlenecks. at the same time, the old -falign-*=1 options are removed, since they were only beneficial for avoiding bloat when global -O3 was used, and in that case, they may have prevented some of the performance gains. to be the most useful, this patch will need further tuning. in particular, research is needed to determine which components should be built with -O3 by default, and it may be desirable to remove the hard-coded -O3 and instead allow more customization of the optimization level used for selected modules.
2013-07-22refactor headers, especially alltypes.h, and improve C++ ABI compatRich Felker-3/+3
the arch-specific bits/alltypes.h.sh has been replaced with a generic alltypes.h.in and minimal arch-specific bits/alltypes.h.in. this commit is intended to have no functional changes except: - exposing additional symbols that POSIX allows but does not require - changing the C++ name mangling for some types - fixing the signedness of blksize_t on powerpc (POSIX requires signed) - fixing the limit macros for sig_atomic_t on x86_64 - making dev_t an unsigned type (ABI matching goal, and more logical) in addition, some types that were wrongly defined with long on 32-bit archs were changed to int, and vice versa; this change is non-functional except for the possibility of making pointer types mismatch, and only affects programs that were using them incorrectly, and only at build-time, not runtime. the following changes were made in the interest of moving non-arch-specific types out of the alltypes system and into the headers they're associated with, and also will tend to improve application compatibility: - netdb.h now includes netinet/in.h (for socklen_t and uint32_t) - netinet/in.h now includes sys/socket.h and inttypes.h - sys/resource.h now includes sys/time.h (for struct timeval) - sys/wait.h now includes signal.h (for siginfo_t) - langinfo.h now includes nl_types.h (for nl_item) for the types in stdint.h: - types which are of no interest to other headers were moved out of the alltypes system. - fast types for 8- and 64-bit are hard-coded (at least for now); only the 16- and 32-bit ones have reason to vary by arch. and the following types have been changed for C++ ABI purposes; - mbstate_t now has a struct tag, __mbstate_t - FILE's struct tag has been changed to _IO_FILE - DIR's struct tag has been changed to __dirstream - locale_t's struct tag has been changed to __locale_struct - pthread_t is defined as unsigned long in C++ mode only - fpos_t now has a struct tag, _G_fpos64_t - fsid_t's struct tag has been changed to __fsid_t - idtype_t has been made an enum type (also required by POSIX) - nl_catd has been changed from long to void * - siginfo_t's struct tag has been removed - sigset_t's has been given a struct tag, __sigset_t - stack_t has been given a struct tag, sigaltstack - suseconds_t has been changed to long on 32-bit archs - [u]intptr_t have been changed from long to int rank on 32-bit archs - dev_t has been made unsigned summary of tests that have been performed against these changes: - nsz's libc-test (diff -u before and after) - C++ ABI check symbol dump (diff -u before, after, glibc) - grepped for __NEED, made sure types needed are still in alltypes - built gcc 3.4.6