36
# If config.make exists, the source directory was configured,
37
# so don't try to be clever and find another directory to build in.
38
ifneq (,$(wildcard $(..)config.make))
41
else # Not configured.
49
# Directory for object files and libc.a. If this is not defined, the
50
# object files live in the subdirectories where their sources live, and
51
# libc.a lives in the parent directory (this probably doesn't work any
54
ifeq ($(filter /%,$(ARCH)),)
55
objdir := $(..)$(ARCH)
61
36
# $(common-objdir) is the place to put objects and
62
37
# such that are not specific to a single subdir.
89
56
# What flags to give to tests which test stack alignment
90
57
stack-align-test-flags =
92
# We have a special subdir for each binary format.
93
# For now, only ELF is fully supported.
96
59
# Complete path to sysdep dirs.
97
60
# `configure' writes a definition of `config-sysdirs' in `config.make'.
98
61
sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))
420
383
LDFLAGS-rtld += $(hashstyle-LDFLAGS)
423
# Command for linking programs with the C library.
425
+link = $(CC) -nostdlib -nostartfiles -o $@ \
426
$(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
427
$(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
428
$(addprefix $(csu-objpfx),$(start-installed-name)) \
429
$(+preinit) $(+prector) \
430
$(filter-out $(addprefix $(csu-objpfx),start.o \
431
$(start-installed-name))\
432
$(+preinit) $(link-extra-libs) \
433
$(common-objpfx)libc% $(+postinit),$^) \
434
$(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
436
386
# Command for linking PIE programs with the C library.
438
388
+link-pie = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
449
399
# Command for statically linking programs with the C library.
450
400
ifndef +link-static
451
+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
401
+link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
452
402
$(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
453
403
$(addprefix $(csu-objpfx),$(static-start-installed-name)) \
454
$(+preinit) $(+prector) \
404
$(+preinit) $(+prectorT) \
455
405
$(filter-out $(addprefix $(csu-objpfx),start.o \
456
406
$(start-installed-name))\
457
407
$(+preinit) $(link-extra-libs-static) \
458
408
$(common-objpfx)libc% $(+postinit),$^) \
459
$(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
409
$(link-extra-libs-static)
410
+link-static-after-libc = $(+postctorT) $(+postinit)
411
+link-static = $(+link-static-before-libc) $(link-libc-static) \
412
$(+link-static-after-libc)
413
+link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
414
$(+link-static-after-libc)
416
# Commands for linking programs with the C library.
418
ifeq (yes,$(build-shared))
419
+link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
420
$(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
421
$(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
422
$(addprefix $(csu-objpfx),$(start-installed-name)) \
423
$(+preinit) $(+prector) \
424
$(filter-out $(addprefix $(csu-objpfx),start.o \
425
$(start-installed-name))\
426
$(+preinit) $(link-extra-libs) \
427
$(common-objpfx)libc% $(+postinit),$^) \
429
+link-after-libc = $(+postctor) $(+postinit)
430
+link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
431
+link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
433
+link = $(+link-static)
434
+link-tests = $(+link-static-tests)
461
437
# Command for statically linking bounded-pointer programs with the C library.
462
438
ifndef +link-bounded
463
439
+link-bounded = $(CC) -nostdlib -nostartfiles -static -fbounded-pointers -o $@ \
464
440
$(sysdep-LDFLAGS) $(LDFLAGS) \
465
441
$(addprefix $(csu-objpfx),b$(static-start-installed-name)) \
466
$(+preinit) $(+prector) \
442
$(+preinit) $(+prectorT) \
467
443
$(filter-out $(addprefix $(csu-objpfx),start.ob \
468
444
$(start-installed-name))\
469
445
$(+preinit) $(link-extra-libs-bounded) \
470
446
$(common-objpfx)libc% $(+postinit),$^) \
471
$(link-extra-libs-bounded) $(link-libc-bounded) $(+postctor) $(+postinit)
447
$(link-extra-libs-bounded) $(link-libc-bounded) $(+postctorT) $(+postinit)
473
449
ifndef config-LDFLAGS
474
450
ifeq (yes,$(build-shared))
480
456
# We need the versioned name of libc.so in the deps of $(others) et al
481
457
# so that the symlink to libc.so is created before anything tries to
482
458
# run the linked programs.
483
link-libc = -Wl,-rpath-link=$(rpath-link) \
459
link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
484
460
$(common-objpfx)libc.so$(libc.so-version) \
485
461
$(common-objpfx)$(patsubst %,$(libtype.oS),c) \
486
$(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed) $(gnulib)
462
$(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
463
link-libc = $(link-libc-before-gnulib) $(gnulib)
464
link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
487
465
# This is how to find at build-time things that will be installed there.
488
466
rpath-dirs = math elf dlfcn nss nis rt resolv crypt
490
468
$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
470
link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
471
link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
491
475
elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
493
nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
494
resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
495
link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
499
477
# Differences in the linkers on the various platforms.
500
478
LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
523
501
# The static libraries.
524
502
link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
503
link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
525
504
link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
506
# How to link against libgcc. Some libgcc functions, such as those
507
# for "long long" arithmetic or software floating point, can always be
508
# built without use of C library headers and do not have any global
509
# state so can safely be linked statically into any executable or
510
# shared library requiring them; these functions are in libgcc.a.
511
# Other functions, relating to exception handling, may require C
512
# library headers to build and it may not be safe to have more than
513
# one copy of them in a process; these functions are only in
514
# libgcc_s.so and libgcc_eh.a.
516
# To avoid circular dependencies when bootstrapping, it is desirable
517
# to avoid use of libgcc_s and libgcc_eh in building glibc. Where any
518
# glibc functionality (in particular, thread cancellation) requires
519
# exception handling, this is implemented through dlopen of libgcc_s
520
# to avoid unnecessary dependencies on libgcc_s by programs not using
521
# that functionality; executables built with glibc do not use
522
# exception handling other than through thread cancellation.
524
# Undefined references to functions from libgcc_eh or libgcc_s may
525
# arise for code built with -fexceptions. In the case of statically
526
# linked programs installed by glibc, unwinding will never actually
527
# occur at runtime and the use of elf/static-stubs.c to resolve these
528
# references is safe. In the case of statically linked test programs
529
# and test programs built with -fexceptions, unwinding may occur in
530
# some cases and it is preferable to link with libgcc_eh or libgcc_s
531
# so that the testing is as similar as possible to how programs will
532
# be built with the installed glibc.
534
# Some architectures have architecture-specific systems for exception
535
# handling that may involve undefined references to
536
# architecture-specific functions. On those architectures,
537
# gnulib-arch and static-gnulib-arch may be defined in sysdeps
538
# makefiles to use additional libraries for linking executables and
539
# shared libraries built by glibc.
528
541
ifneq ($(have-cc-with-libunwind),yes)
531
544
libunwind = -lunwind
533
546
libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
534
gnulib := -lgcc $(libgcc_eh)
535
static-gnulib := -lgcc -lgcc_eh $(libunwind)
548
gnulib = -lgcc $(gnulib-arch)
549
gnulib-tests := -lgcc $(libgcc_eh)
551
# By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
552
# statically link programs. When --disable-shared is used, we use
553
# -lgcc_eh since elf/static-stubs.o isn't sufficient.
554
ifeq (yes,$(build-shared))
555
static-gnulib = -lgcc $(static-gnulib-arch)
557
static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
559
static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
536
560
libc.so-gnulib := -lgcc
538
562
+preinit = $(addprefix $(csu-objpfx),crti.o)
542
566
# Variants of the two previous definitions for linking PIE programs.
543
567
+prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
544
568
+postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
569
# Variants of the two previous definitions for statically linking programs.
570
+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
571
+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
545
572
+interp = $(addprefix $(elf-objpfx),interp.os)
546
573
csu-objpfx = $(common-objpfx)csu/
547
574
elf-objpfx = $(common-objpfx)elf/
576
# A command that, prepended to the name and arguments of a program,
577
# and run on the build system, causes that program with those
578
# arguments to be run on the host for which the library is built.
580
test-wrapper = $(cross-test-wrapper)
582
# Likewise, but the name of the program is preceded by
583
# <variable>=<value> assignments for environment variables.
584
ifndef test-wrapper-env
585
test-wrapper-env = $(test-wrapper) env
588
# Whether to run test programs built for the library's host system.
589
ifndef run-built-tests
590
ifeq (yes|,$(cross-compiling)|$(test-wrapper))
593
run-built-tests = yes
549
597
# How to run a program we just linked with our library.
550
598
# The program binary is assumed to be $(word 2,$^).
551
599
built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
555
603
$(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
556
604
$(filter -Wl$(comma)-rpath-link=%,\
557
605
$(sysdep-LDFLAGS)))))
558
# Never use $(run-via-rtld-prefix) for the statically-linked %-bp test
559
# programs, or for tests listed in tests-static or xtests-static.
606
# $(run-via-rtld-prefix) is a command that, when prepended to the name
607
# of a program built with the newly built library, produces a command
608
# that, executed on the host for which the library is built, runs that
609
# program. For the statically-linked %-bp test programs, and for
610
# tests listed in tests-static or xtests-static, it is empty.
560
611
run-via-rtld-prefix = \
561
612
$(if $(strip $(filter $(notdir $(built-program-file)), \
562
613
$(tests-static) $(xtests-static)) \
567
618
run-via-rtld-prefix =
569
run-program-prefix = $(cross-test-wrapper) $($*-WRAPPER) \
570
$(run-via-rtld-prefix)
571
built-program-cmd = $(cross-test-wrapper) $($*-WRAPPER) \
620
# $(run-program-prefix) is a command that, when prepended to the name
621
# of a program built with the newly built library, produces a command
622
# that, executed on the build system on which "make" is run, runs that
624
run-program-prefix = $(test-wrapper) $(run-via-rtld-prefix)
625
# $(built-program-cmd) is a command that, executed on the build system
626
# on which "make" is run, runs the newly built program that is the
627
# second dependency of the makefile target in which
628
# $(built-program-cmd) is used.
629
built-program-cmd = $(test-wrapper) \
572
630
$(run-via-rtld-prefix) $(built-program-file)
574
# Same as built-program-cmd, but without the cross-test-wrapper. Used
575
# to run programs from the test machine, as in nptl/tst-cancel7.
576
local-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
631
# $(host-built-program-cmd) is a command that, executed on the host
632
# for which the library is built, runs the newly built program that is
633
# the second dependency of the makefile target in which
634
# $(host-built-program-cmd) is used.
635
host-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
961
1015
grp pwd posix io termios resource misc socket sysvipc gmon \
962
1016
gnulib iconv iconvdata wctype manual shadow gshadow po argp \
963
1017
crypt nss localedata timezone rt conform debug \
964
$(add-on-subdirs) $(dlfcn) $(binfmt-subdir)
1018
$(add-on-subdirs) dlfcn elf
966
1020
ifndef avoid-generated
967
1021
all-Depend-files := $(wildcard $(foreach dir,$(all-subdirs),\
995
1049
sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
996
1050
$(firstword $(subst :, ,$p))))
1052
# A sysdeps Makeconfig fragment may set libc-reentrant to yes.
1053
ifeq (yes,$(libc-reentrant))
1054
defines += -D_LIBC_REENTRANT
1056
libio-mtsafe = -D_IO_MTSAFE_IO
998
1059
endif # Makeconfig not yet included
1000
1061
# Local Variables: