Commit Graph

52 Commits

Author SHA1 Message Date
Konstantin Belousov
51015e6d0f csu: move common code to libc
Why? Most trivial point, it shaves around 600 bytes from the dynamic
binaries on amd64. Less trivial, the removed code is no longer part of
the ABI, and we can ship updates to it with libc updates. Right now most
of the csu is linked into the binaries and require us to do somewhat
tricky ABI compat when it needs to change. For instance, the init_array
change would be much simpler and does not require note tagging if we
have init calling code in libc.

This could be improved more, by splitting dynamic and static
initialization. For instance, &_DYNAMIC tests can be removed then.
Such change, nonetheless, would require building libc three times.
I left this for later, after this change stabilizes, if ever.

Reviewed by:	markj
Discussed with:	jrtc27 (some objections, see the review), imp
Tested by:	markj (aarch64)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
Differential revision:	https://reviews.freebsd.org/D37220
2023-03-12 00:50:03 +02:00
John Baldwin
b0ee263dbd Consolidate duplicated logic in csu Makefiles to lib/csu/Makefile.inc.
Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D25537
2020-07-03 00:09:41 +00:00
John Baldwin
99282790b7 Remove the sed hack for ABI tag notes.
The ELF notes compiled in C were placed in a section with the wrong type
(SHT_PROGBITS instead of SHT_NOTE).  Previously, sed was used on the
generated assembly to rewrite the section type.  Instead, write the notes
in assembly which permits setting the correct section type directly.

While here, move inline assembly entry points out of C and into assembly
for aarch64, arm, and riscv.

Reviewed by:	kib
Tested on:	amd64 (cirrus-ci), riscv64
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D25211
2020-06-15 19:38:48 +00:00
Brandon Bergren
3dbb9df36b [PowerPC] Fix wrong instructions in _savegpr_X.
We were accidentally using stfd instead of stw in our SAVEGPR macro.

This has almost certainly been causing crashes when compiling with -Os.

Reviewed by:	jhibbits (in irc)
MFC after:	3 days
Sponsored by:	Tag1 Consulting, Inc.
2020-05-14 04:00:35 +00:00
Justin Hibbits
6b672ba642 [PowerPC] force applications linked with lib CSU to have .got
Summary:
This forces applications linked with lib CSU to have a .got, fixing binaries
linked with LLD9 after secure-plt was enabled on FreeBSD.

Submitted by:	Alfredo Dal'Ava Junior (alfredo.junior_eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D21476
2019-10-12 20:53:40 +00:00
Justin Hibbits
5d031e332f Create crtsavres.o for powerpc builds
Summary:
GCC expects to link in a crtsavres.o on powerpc platforms.  On
powerpc64 this is an empty file, but on powerpc and powerpcspe this does contain
some save/restore functions, which may not actually be necessary for newer
modern GCC and clang.  This appeases the in-tree gcc, though, and is needed in
order to switch to the BSD CRTRBEGIN.

PR:	233751
Reviewed By: andrew
Differential Revision: https://reviews.freebsd.org/D18826
2019-01-12 21:29:54 +00:00
Andrew Turner
8522d140a5 Build the csu tests on all architectures.
The tests haven't been run them, but this is enough to build them so I can
get feedback on if the various crt.h headers are correct.

MFC with:	r339738
Sponsored by:	DARPA, AFRL
2018-10-30 14:44:12 +00:00
Konstantin Belousov
bdafb02fcb Process irelocs for statically linked binaries from crt1 on x86.
This makes statically linked binaries with ifuncs operational.

Reported and tested by:	mjg
Reviewed by:	emaste, markj
Sponsored by:	The FreeBSD Foundation
Approved by:	re (rgrimes)
Differential revision:	https://reviews.freebsd.org/D17363
2018-10-13 23:52:55 +00:00
Pedro F. Giffuni
5e53a4f90f lib: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-26 02:00:33 +00:00
Eitan Adler
a2aef24aa3 Update several more URLs
- Primarily http -> https
- Primarily FreeBSD project URLs
2017-10-29 08:17:03 +00:00
John Baldwin
5944f899a2 Rework r234502 to include a modified CFLAGS along with ACFLAGS.
On most architectures crt objects are compiled in a multiple-step process
so that sed can be run on the generated assembly.  As the final step,
the C compiler generates an object file from the modified assembly output.
Currently this last step uses $CC with only $ACFLAGS.  However, for other
uses in the tree, $ACFLAGS is meant to include assembly-specific compiler
flags that are in addition to $CFLAGS (see default .S.o rules
bsd.suffixes.mk).  In particular, external toolchains may require
additional flags to select a non-default target which will be present
in CFLAGS but not ACFLAGS.  To support this while still mitigating the
issue with CFLAGS described in r234502, include a modified CFLAGS that
excludes "-g" when assembling the modified assembly files.

Note that normally an assembler ($AS) is used to assemble .s flags to
object files (see bsd.suffixes.mk).  However, llvm-based toolchains do
not currently have a stand-alone assembler.

Reviewed by:	imp
Sponsored by:	DARPA / AFRL
Differential Revision:	https://reviews.freebsd.org/D10085
2017-04-07 19:53:14 +00:00
Enji Cooper
23f6875a43 Use SRCTOP-relative paths and .CURDIR with :H instead of ".." specified paths
This implifies pathing in make/displayed output

MFC after:    3 weeks
Sponsored by: Dell EMC Isilon
2017-01-20 03:52:16 +00:00
Ed Maste
c6a33c8e88 Remove historical GNUC test
The requirement is for a GCC-compatible compiler and not necessarily
GCC itself. However, we currently expect any compiler used for building
the whole of FreeBSD to be GCC-compatible and many things will break if
not; there's no longer a need to have an explicit test for this in csu.

Sponsored by:	The FreeBSD Foundation
2015-12-08 19:32:58 +00:00
Bryan Drewery
ec766071e3 META_MODE: Remove DEP_MACHINE from Makefile.depend files.
This has not been needed since r246865 in projects/bmake.

Sponsored by:	EMC / Isilon Storage Division
2015-09-25 19:44:01 +00:00
Bryan Drewery
54c7d75a06 META_MODE: Remove DEP_RELDIR from Makefile.depend files.
This has not been needed since r284171 in projects/bmake.

Sponsored by:	EMC / Isilon Storage Division
2015-09-25 19:26:08 +00:00
Bryan Drewery
7c6cc9de3a Fix installation of 32bit libraries after r288074.
FILES is not used when LIBRARIES_ONLY is set, which is used to build and
install the lib32 sysroot.  All of the csu files do quality as "libraries"
for this case so just undefine LIBRARIES_ONLY.

This is still better than the previous realinstall handling as it does
not hook into META_MODE properly.

Sponsored by:	EMC / Isilon Storage Division
2015-09-21 21:44:02 +00:00
Bryan Drewery
5ca34122ec Replace realinstall: and META_MODE staging hacks with FILES mechanism.
This partially reverts r270170 for lib/csu/i386 while retaining the
change for using bsd.lib.mk.

These FILES groups could go into lib/csu/Makefile.inc but I've kept them
in the Makefiles for clarity.

Sponsored by:	EMC / Isilon Storage Division
2015-09-21 18:39:13 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Konstantin Belousov
d549ead6a9 Only assign the environ in the startup code when environ is NULL.
Preloaded library could have changed the environment, and
unconditional assingment to the environ undoes the customization.
The binaries needs to be recompiled to get the fix.

Move the common code to set up environ and __progname into the helper.
Note that ia64 possibly not fixed, due to it still using old csu.

Reported and tested by:	John Hein <jhein@symmetricom.com>
Reviewed by:	kan, scf
Approved by:	secteam (simon)
MFC after:	2 weeks
2013-01-07 17:58:27 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Dimitry Andric
db3212b375 Revert r234356 for now, as it leads to run-time problems on 32-bit
PowerPC.  Note this will break world.

Reported by:	andreast
Pointy hat to:	dim
2012-04-23 06:33:27 +00:00
Dimitry Andric
d2cc835cb5 After r217375, some startup objects under lib/csu are built in a special
way: first they are compiled to assembly, then some sed'ing is done on
the assembly, and lastly the assembly is compiled to an object file.

This last step is done using ${CC}, and not ${AS}, because when the
compiler is clang, it outputs directives that are too advanced for our
old gas.  So we use clang's integrated assembler instead.  (When the
compiler is gcc, it just calls gas, and nothing is different, except one
extra fork.)

However, in the .s to .o rules in lib/csu/$ARCH/Makefile, I still passed
CFLAGS to the compiler, instead of ACFLAGS, which are specifically for
compiling .s files.

In case you are using '-g' for debug info anywhere in your CFLAGS, it
causes the .s files to already contain debug information in the assembly
itself.  In the next step, the .s files are also compiled using '-g',
and if the compiler is clang, it complains: "error: input can't have
.file dwarf directives when -g is used to generate dwarf debug info for
assembly code".

Fix this by using ${ACFLAGS} for compiling the .s files instead.

Reported by:	jasone
MFC after:	1 week
2012-04-20 21:00:39 +00:00
Dimitry Andric
4f78aa4725 Work around an issue on 32-bit PowerPC, where clang executable can get
too big, causing 'relocation truncated to fit' errors at link time.

Reviewed by:	nwhitehorn
2012-04-16 21:36:55 +00:00
Konstantin Belousov
a22748dbd9 Stop calling _init/_fini methods from crt1 for dynamic binaries. Do
call preinit, init and fini arrays methods from crt1 for static binaries.

Mark new crt1 with FreeBSD-specific ELF note.

Move some common crt1 code into new MI file ignore_init.c, to reduce
duplication.  Also, conservatively adjust nearby sources for style.

Reviewed by:	kan
Tested by:	andrew (arm), flo (sparc64)
MFC after:	3 weeks
2012-03-11 20:04:09 +00:00
Konstantin Belousov
33e6b543c7 Mark csu on PowerPC as not requiring executable stack.
Reviewed and tested by:	nwhitehorn
2011-01-14 11:34:58 +00:00
Dimitry Andric
9ef4e3afcb Apply a workaround for a binutils issue with the .note.ABI-tag section
generated from lib/csu/common/crtbrand.c (which ultimately ends up in
executables and shared libraries, via crt1.o, gcrt1.o or Scrt1.o).

For all arches except sparc, gcc emits the section directive for the
abitag struct in crtbrand.c with a PROGBITS type.  However, newer
versions of binutils (after 2.16.90) require the section to be of NOTE
type, to guarantee that the .note.ABI-tag section correctly ends up in
the first page of the final executable.

Unfortunately, there is no clean way to tell gcc to use another section
type, so crtbrand.c (or the C files that include it) must be compiled in
multiple steps:

- Compile the .c file to a .s file.
- Edit the .s file to change the 'progbits' type to 'note', for the section
  directive that defines the .note.ABI-tag section.
- Compile the .s file to an object file.

These steps are done in the invididual Makefiles for each applicable arch.

Reviewed by:	kib
2011-01-13 20:44:31 +00:00
Dimitry Andric
cbbcfbf8b7 Let all .c and .S files under lib/csu consistently use the __FBSDID()
macro for identification, instead of several different hand-rolled
variants (plain .ident, .ascii, etc).
2010-12-09 21:31:21 +00:00
Ulrich Spörlein
03dab16e1d Use default WARNS setting (of 6) for lib/csu.
PR:		bin/140089
Reviewed by:	jmallett
Approved by:	ed (co-mentor)
2010-03-05 13:29:05 +00:00
Ulrich Spörlein
98b77738b8 Properly declare non-extern functions in crt1
Also move the declarations after __progname consistently to
make the distinction clearer.

Reviewed by:	jmallett
Approved by:	ed (co-mentor)
2010-03-05 13:28:05 +00:00
Konstantin Belousov
c09ba32715 Properly support -fPIE by linking PIE binaries with specially-built
Scrt1.o instead of crt1.o, since the later is built as non-PIC.

Separate i386-elf crt1.c into the pure assembler part and C code,
supplying all data extracted by assembler stub as explicit parameters [1].
Hide and localize _start1 symbol used as an interface between asm and
C code.

In collaboration with:	kan
Inspired by:	PR i386/127387 [1]
Prodded and tested by:	rdivacky [1]
MFC after:	3 weeks
2009-12-02 16:34:20 +00:00
Doug Rabson
ccd13c49b5 Add support for TLS in statically linked programs. 2004-08-15 16:18:52 +00:00
Mark Murray
818c8b696b make these more useful for lint(1). Minor diff-reductions while I'm
about it.
2003-01-26 23:14:47 +00:00
Ruslan Ermilov
d2893b161b Drop support for COPY, -c has been the default mode of install(1)
for a long time now.

Approved by:	bde
2002-07-29 09:40:17 +00:00
Mark Murray
828191256b The main reason for this is to reduce diffs between all the crt1.c's.
Assembler macros are tidied up and made as similar as sanely possible.
The macros are translated into C (__inline static) functions for lint.

Declaration orders are made the same.
Declarations are all ISOfied and tidied up.

Comment contents have gratuitous diffs removed.

The net result is a bunch of crt1.c's that are 90% the same.
It may be possible to now encapsulate the differences in one
MD header, and have only one MI crt1.c file (although the macros
to do this may be ugly).

Helpful comments by:	obrien, bde
Alpha tested by:	des
i386-elf tested by:	markm
2002-07-16 12:28:50 +00:00
David E. O'Brien
d03f581f32 Use .rodata section for $FreeBSD$. 2002-05-15 04:19:49 +00:00
Ruslan Ermilov
2020063860 Fixed CLEANFILES after bsd.lib.mk sweep. 2002-05-13 15:28:00 +00:00
Ruslan Ermilov
7893b524b9 SOBJS are not used here for a long time, and were just
pessimising the `install'.
2002-05-13 11:51:11 +00:00
Ruslan Ermilov
2a53f3fb35 Major cleanup of bsd.lib.mk.
Get rid of the INTERNALSTATICLIB knob and just use plain INTERNALLIB.
INTERNALLIB now means to build static library only and don't install
anything.  Added a NOINSTALLLIB knob for libpam/modules.  To not
build any library at all, just do not set LIB.
2002-05-13 10:53:24 +00:00
Ruslan Ermilov
5b8f41af39 Revert the last change. The corresponding bsd.lib.mk changes were
already backed out.
2002-05-12 16:21:23 +00:00
David E. O'Brien
785b36d40f Use the simpler NOMAN rather than NOMAN, NOPIC, NOPROFILE, INTERNALLIB. 2002-05-11 17:45:03 +00:00
Mark Murray
4cd0119367 Do not use __progname directly (except in [gs]etprogname(3)).
Also, make an internal _getprogname() that is used only inside
libc. For libc, getprogname(3) is a weak symbol in case a
function of the same name is defined in userland.
2002-03-29 22:43:43 +00:00
David E. O'Brien
a378c419fe Remove prototype, no other crt1.c has or needs it. 2002-03-23 18:14:04 +00:00
David E. O'Brien
674c351892 Remove __P() usage. 2002-03-22 09:16:59 +00:00
David E. O'Brien
4d826ecfbc Remove __P() usage. 2002-03-21 23:43:04 +00:00
David E. O'Brien
1e23f97e5c Minor style(9) nit + utilize ELF features for the FreeBSD ID. 2002-02-27 22:13:02 +00:00
David E. O'Brien
60ed6ae069 Sync with other platforms. 2001-10-27 08:32:07 +00:00
Ruslan Ermilov
8af1452cf8 Removed duplicate VCS ID tags, as per style(9). 2001-08-13 14:06:34 +00:00
Mark Peek
4f1fda9595 Fix compilation errors by adding forward declarations and fix typo. 2001-07-31 16:10:51 +00:00
David E. O'Brien
6e88ecec2c The instructions on doing something with src/lib/csu/powerpc. 2001-01-04 10:27:04 +00:00