aboutsummaryrefslogtreecommitdiff
path: root/lib/csu/common
Commit message (Collapse)AuthorAgeFilesLines
* csu: drop support for GCJBrooks Davis2025-04-182-37/+0
| | | | | | | | | | | | | | | | | | | | Remove .jcr sections and related infrastructure. This has no impact on existing binaries and the toolchain remains capability of linking them, but would require different (or additional) csu files. GCC removed GCJ from trunk in on September 30, 2016. Our support came in with D17587 for compatibility with old object files. It was roughly contemporaneous with GCC 6.5, the last release with GCJ support. At this point we don't even have a compiler port capable of producing GCJ binaries so there is no need to carry this around any more. For reference see: https://en.wikipedia.org/wiki/GNU_Compiler_for_Java#History Reviewed by: kib, emaste Discussed with: imp Sponsored by: SRI International Differential Revision: https://reviews.freebsd.org/D49882
* crtend: accurately check for the start of .ctorsKonstantin Belousov2025-01-281-2/+9
| | | | | | | | | | | | For the hypothetic situation where crtbegin.o is not linked into the binary, but crtend.o is, which results in the missing starting sentinel in the ctors array, be careful to not iterate past the start of the section. Reviewed by: andrew, dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D48700
* crtbegin: accurately check for the end of .dtorsKonstantin Belousov2025-01-281-1/+9
| | | | | | | | | | | | not relying only on the end section marker, but also checking for the section size when iterating. Reported by: kargl Analyzed by: dim Reviewed by: andrew, dim Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D48700
* csu: add the "Retain" flag to notes sections flagKonstantin Belousov2025-01-243-3/+3
| | | | | | | | It should make the notes immune against --gc-sections. Reported and tested by: bapt Sponsored by: The FreeBSD Foundation MFC after: 1 week
* lib: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* csu: Teach csu about PAC and BTIAndrew Turner2023-10-303-0/+15
| | | | | | | | | | | | | | | | | Add the Branch Target Identification (BTI) note to libc assembly sources and Pointer Authentication Code (PAC) instructions to _init and _fini. _init and _fini may be called indirectly so need a BTI landing pad. As they are non-leaf functions use the appropriate PAC instruction that also guards against changing the link register. As all object files need the note for any binary using these object files we need to insert it in all asm files. Reviewed by: markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D42227
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-165-10/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-123-3/+3
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* csu: move common code to libcKonstantin Belousov2023-03-112-140/+50
| | | | | | | | | | | | | | | | | | | | | | 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
* csu: Add missing GNU-stack annotations to note object files.John Baldwin2022-11-183-0/+6
| | | | | | ld.bfd marks the stack as executable for the crt objects due to the missing annotations which raises a fatal warning starting with version 2.39.
* Rename __JCR_LIST__ to __JCR_END__ in crtend.c.John Baldwin2020-11-101-1/+1
| | | | | | | | | | | | | | This is more consistent with the names used for .ctor and .dtor symbols and better reflects __JCR_END__'s role. Reviewed by: andrew Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27125 Notes: svn path=/head/; revision=367574
* Include ABI note tag in shared libraries.John Baldwin2020-07-162-11/+43
| | | | | | | | | | | | | Split the ELF feature note into a separate file that is linked into *crt1.o the same as crtbrand.S was before. crtbrand.o is now linked into crti.o on all platforms in addition to *crt1.o. Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D25304 Notes: svn path=/head/; revision=363263
* Remove the sed hack for ABI tag notes.John Baldwin2020-06-154-101/+102
| | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=362203
* csu: Fix dynamiclib/init_test:jcr_test on !HAVE_CTORS archsKyle Evans2019-11-081-4/+6
| | | | | | | | | | | | | | | .jcr still needs a 0-entry added in crtend, even on !HAVE_CTORS archs, as we're still getting .jcr sections added -- presumably due to the reference in crtbegin. Without this terminal, the .jcr section (without data) overlaps with the next section and register_classes in crtbegin will be examining the wrong item. PR: 241439 Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D22132 Notes: svn path=/head/; revision=354541
* Add the missing 0 at the end of the .jcr section.Andrew Turner2018-11-241-0/+3
| | | | | | | | Without this the dynamic library test was failing as it was calling _Jv_RegisterClasses multiple times. Notes: svn path=/head/; revision=340910
* csu: use BSD-1-clause license on csu filesEd Maste2018-11-202-8/+2
| | | | | | | | | | Copyright on these files is held by kib@ and/or the Foundation, and both agree to this change. Approved by: kib Notes: svn path=/head/; revision=340702
* Add NT_FREEBSD_FEATURE_CTL ELF note to csuEd Maste2018-11-201-0/+15
| | | | | | | | | | | | | | This note will be used to allow binaries to opt out of, or in to, upcoming vulnerability mitigation and other features. It is not yet connected but being added now to facilitate testing and ensure compatibility with existing kernels and tools. Reviewed by: brooks, jhb, kib, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17438 Notes: svn path=/head/; revision=340701
* Run __cxa_finalize in shared objects in the destructor path.Andrew Turner2018-11-131-3/+24
| | | | | | | | | | | | When we have .dtors call them before .dtor handling, otherwise call from a destructor. PR: 233056 MFC with: r339738 Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=340395
* Add __used to __CTOR_LIST__ and __DTOR_LIST__Ed Maste2018-10-311-2/+2
| | | | | | | | | | | | | | | | Enabling BSD_CRTBEGIN on amd64 resulted in error: unused variable '__CTOR_LIST__'. __CTOR_LIST__ is indeed unused in crtbegin.c; it marks the beginning of the .ctors array and is used in crtend.c. Annotate __DTOR_LIST__ as well for consistency. Discussed with: andrew MFC with: r339738 Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=339954
* Make the .ctors, .dtors, and .jcr markers as static. They shouldn't beAndrew Turner2018-10-292-5/+5
| | | | | | | | | | accessible from out of the files they are defined in. MFC with: r339738 Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=339866
* Add __dso_handle to the BSD crtbegin. This is used to identify sharedAndrew Turner2018-10-261-0/+8
| | | | | | | | | | objects. MFC with: r339738 Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=339773
* Implement a BSD licensed crtbegin/crtendAndrew Turner2018-10-252-0/+163
| | | | | | | | | | | | | | | | | These are needed for .ctors/.dtors and .jcr handling. The former needs all the function pointers to be called in the correct order from the .init/.fini section. The latter just needs to call a gcj specific function if it exists with a pointer to the start of the .jcr section. This is currently disabled until __dso_handle support is added. Reviewed by: emaste MFC after: 1 month Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17587 Notes: svn path=/head/; revision=339738
* Process irelocs for statically linked binaries from crt1 on x86.Konstantin Belousov2018-10-131-1/+39
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=339351
* crt: switch to standard note type definitions from elf_common.hEd Maste2018-10-043-6/+5
| | | | | | | | | | | | | | This makes it easier to grep the source tree for these notes, and ensures that they will remain in sync. Reviewed by: kib Approved by: re (gjb) MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17408 Notes: svn path=/head/; revision=339181
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-263-0/+6
| | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=326219
* Add an elf note on ARM to store the MACHINE_ARCH an executable was builtAndrew Turner2013-09-261-0/+1
| | | | | | | | | | | | | for. This is useful for software needing to know which architecture a binary is built for as arm and armv6 have slight differences meaning only some binaries build for one will work as expected on the other. It is expected pkgng will be able to make use of this to simplify the logic to determine which package ABI to use. Approved by: re (kib) Notes: svn path=/head/; revision=255874
* Only assign the environ in the startup code when environ is NULL.Konstantin Belousov2013-01-071-5/+9
| | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=245133
* Stop calling _init/_fini methods from crt1 for dynamic binaries. DoKonstantin Belousov2012-03-112-15/+126
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=232832
* Add a header with definitions useful for constructing ELF notes.Konstantin Belousov2012-03-111-0/+38
| | | | | | | | Reviewed by: kan MFC after: 3 weeks Notes: svn path=/head/; revision=232830
* Apply a workaround for a binutils issue with the .note.ABI-tag sectionDimitry Andric2011-01-131-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=217375
* The __used (== __attribute__((__used)) ) silences the warning producedKonstantin Belousov2007-12-041-1/+1
| | | | | | | | | by unreferenced symbol. Apply __used instead of rev. 1.5. Requested by: kan Notes: svn path=/head/; revision=174251
* Restore the branding of the ELF executables. The structure was optimized out.Konstantin Belousov2007-12-031-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=174218
* GC these crt{begin,end}.c, which are unused since the last FreeBSD platformMarius Strobl2006-05-222-114/+0
| | | | | | | switched to those created from GCC's crtstuff.c 4 years ago. Notes: svn path=/head/; revision=158836
* Explicitly specify an alignment for abitag. Without it, gcc specifies aPeter Wemm2003-10-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | section alignnment of 16 bytes for amd64 and this breaks file(1). Before: ./cp: ELF 64-bit LSB executable, AMD x86-64, version 1 (FreeBSD), for \ FreeBSD 127.7.9, statically linked, stripped after: ^^^^^^^ ./ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (FreeBSD), for \ FreeBSD 5.0.1, dynamically linked (uses shared libs), stripped The reason for this is that the NOTE sections are not contiguous internally. If the note section has an alignment of 16, then anything that looks for the data is supposed to round up the payload start to the next multiple of the alignment. But FreeBSD/amd64 broke because the structure is declared as a single structure, not a (header,payload) group, where the payload had an explicit alignment roundup. The alternative is to change things like file(1) to ignore the ELF payload alignment rules for the PT_NOTE section only for FreeBSD. Notes: svn path=/head/; revision=121160
* Set abitag __unused.David E. O'Brien2003-05-041-3/+4
| | | | Notes: svn path=/head/; revision=114666
* Fix the copyright dates.David E. O'Brien2002-05-071-1/+1
| | | | Notes: svn path=/head/; revision=96171
* GC code that moved to crtbrand.c.David E. O'Brien2002-01-281-4/+0
| | | | Notes: svn path=/head/; revision=89930
* Feh, it helps to include a file other than yourself... wonder howDavid E. O'Brien2001-10-271-1/+1
| | | | | | | | | GCC cpp liked that. Properly include the branding info. Notes: svn path=/head/; revision=85592
* * Bring back the guts of crt{i,n}.S. This allows C++ exceptions to workDavid E. O'Brien2000-10-282-18/+52
| | | | | | | | | | | | | | | | | | | | | | when using the egcs and gcc-devel ports, along with GCC built from stock public FSF sources. With out this change, FreeBSD will be removed from the list of systems GCC 3.0 must be evaluated on before release. With the effort some of us put into getting FreeBSD on this list, we should not turn this effort into a waste, else we might not be worth fighting for in the future. (note that Alpha and IA-64 versions of crt{i,n}.S are needed) * Switch from our own crt{begin,in} to those created from GCC's crtstuff.c. This will allow us to switch to DWARF2 exceptions in the future, along with staying in sync with any future GCC requirements. * Break out our ELF branding bits into a seperate file. Currently this is now included by our crt1.c files (since this functionality was part of our native crtbegin.c). Later crtbrand.o will be merged in the creation of crti.o. Notes: svn path=/head/; revision=67811
* This is step 1 in an effort to unify the start-up files for theJohn Polstra2000-05-191-7/+50
| | | | | | | | | | | | | | | | | | | | various architectures. Now all the work is done in crtbegin.c. It doesn't contain any assembly language code, so it should work fine on all architectures. (I have tested it on the i386 and the alpha.) The old assembly language files crt[in].S are now empty shells that generate no code or data. They should not be removed any time soon, because the various versions of gcc in src and ports expect them to exist. Next I will move crtbegin.c into a new common machine-independent directory, and adjust the i386-elf Makefile to use that version. After that I will adjust the alpha Makefile to use the common version too. Requested by: obrien Notes: svn path=/head/; revision=60698
* $Id$ -> $FreeBSD$Peter Wemm1999-08-282-2/+2
| | | | Notes: svn path=/head/; revision=50476
* Reverse the order of processing object files within an executable orJohn Polstra1999-03-131-3/+3
| | | | | | | | | | | | | | | | shared library when invoking global constructors and destructors. For constructors, the object files used to be processed from first to last; now they're done from last to first. (Destructors are done in the opposite order, as required by the C++ standard.) This makes us consistent with standard gcc and egcs compilers. It also eliminates ordering differences between dynamic and static executables. Bump the value of __FreeBSD_version to 400002 to reflect this change. Notes: svn path=/head/; revision=44699
* Move the code for the ".init" and ".fini" sections outside of aJohn Polstra1999-03-122-13/+13
| | | | | | | | | | | | C function so the compiler won't try to emit line numbers for it with "-g", breaking the build. This has the nice side-effect of making crtbegin.o and crtbeginS.o a little bit smaller. Remove "-Wno-unused" from the Makefile. Replace it with "__unused" on particular function and variable declarations. Notes: svn path=/head/; revision=44691
* Import C startup files for ELF support.John Polstra1998-03-072-0/+92
Submitted by: John Polstra <jdp@polstra.com> Notes: svn path=/cvs2svn/branches/JDP/; revision=34198