Commit graph

229 commits

Author SHA1 Message Date
Martin Tournoij f122045e36 crunchgen: add --list option
"bsdbox --list" will print all tools in the binary, one per line. The
main use case for this is to make it easier to create links:

	for t in $(bsdbox --list); do
		ln -s bsdbox $t
	done

The name --list was taken from busybox.

This just adds a new "program" with the name "--list". I don't think we
need to do real argument parsing here, and this is also how busybox does
it.

An additional minor change is that just "bsdbox" will no longer print
the binary name itself ("bsdbox" in this case). Before it would do:

	% bsdbox
	usage: boxlike <prog> <args> ..., where <prog> is one of:
	 cp ls mv bsdbox

And now just:

	% bsdbox
	usage: boxlike <prog> <args> ..., where <prog> is one of:
	 cp ls mv

And just "bsdbox" will also exit with code 0 (and print to stdout)
rather than exit with 0 and print to stderr

Example output:

	% ./bsdbox
	usage: bsdbox program [args ...]
	       bsdbox --list
	       program [args ...]

	bsdbox combines several programs in one executable. Create a link to this
	executable with the program name to run that program, or give the program
	name as the first argument.

	Currently defined programs:
	 true false tail head uname

	% ./bsdbox --list
	true
	false
	tail
	head
	uname

	% ./bsdbox uname -a
	FreeBSD freebsd 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64

	% ln -s bsdbox uname
	% ./uname -a
	FreeBSD freebsd 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64

Pull Request:	https://github.com/freebsd/freebsd-src/pull/894
Signed-off-by: Martin Tournoij <martin@arp242.net>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/894
2024-04-17 12:07:25 -06:00
Elyes Haouas ec8a394d9c usr.sbin: Remove repeated words
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/887
2024-04-11 11:53:37 -06:00
Elyes Haouas e57d2e4aee crunch: Fix typo
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/882
2024-04-11 11:40:40 -06:00
Kyle Evans 6e2cfb24ee crunchgen: slap a dependency on the generated makefile for .lo
crunchgen generates a foo.lo for each binary it will end up crunching
into the final product.  While they have a dependency on the libs that
are used to link them, nothing will force relinking if the set of libs
needed to link them is changed.  Because of this, incremental builds may
not be possible if one builds a version of, e.g., rescue/ with a broken
set of libs specified for a project -- a subsequent fix won't be rolled
in cleanly, it will require purging the rescue/ objdir.

This is a bit crude, but the foo.mk we generate doesn't actually get
regenerated all that often in practice, so a spurious relink for the
vast majority of crunched objects won't actually happen all that often.

Reviewed by:	bapt, emaste, imp
Differential Revision:	https://reviews.freebsd.org/D43869
2024-03-08 20:01:25 -06:00
Ed Maste 1f41c1c1a3 crunch: remove fdisk from examples
It has been deprecated for a long time; gpart should be used instead.
The man page was updated in 2015 to declare it obsolete (b8c19fd719).
2024-01-24 09:12:19 -05:00
Warner Losh 4d65a7c695 usr.sbin: Automated cleanup of cdefs and other formatting
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
2023-11-26 22:24:01 -07:00
Kyle Evans 8f2848eafa crunchgen: fix "keep" for an ELF world, break it out
"keep" currently adds a leading underscore, which hasn't been useful or
accurate since a.out days.  Preserve the symbol name as it's given
rather than mangle it to match ELF-style symbol names.

This was partially fixed back in
6cd35234a0 ("Assume ELF-style symbol names now.") for crunchgen, but
the keeplist wasn't changed to match it.

While we're here, break it out to bsd.crunchgen.mk for later use in
bsdbox.

Reviewed by:	adrian, imp
Differential Revision:	https://reviews.freebsd.org/D42499
2023-11-09 22:33:58 -06:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Alfonso Gregory 72e1ea2f13 Mark usage function as __dead2 in programs where it does not return
In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735
2023-07-07 10:45:18 -06:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Gordon Bergling d34de8d378 crunchide(1): Fix a typo in a comment
- s/maek/make/

Obtained from:	NetBSD
MFC after:	3 days
2022-07-16 13:32:47 +02:00
Fangrui Song ec81497cc7 crunchgen: remove -dc from linker invocation
In GNU ld and ld.lld, -dc is used with -r to allocate space to COMMON
symbols.  It is presumably to work around legacy code which cannot
handle COMMON symbols in relocatable output.  ld.lld may remove -dc or
make it a no-op for the 15.0.0 release.

As of 7420b323a0 crunch/crunchide does not require -dc, as the symbol
hiding technique no longer relied on making symbols local.

In addition -fno-common is now the default in Clang and GCC, so -dc
serves no purpose as the compiler does not generate COMMON symbols
anyway.

See https://maskray.me/blog/2022-02-06-all-about-common-symbols for more
detail on common symbols.

Reviewed by:	emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D34215
2022-02-09 13:54:35 -05:00
Alexey Dokuchaev ccfdf335d6 crunchgen: use realpath(3) instead of ``pwd -P''
r366466 (9c7bd4f198) fixed a subtle bug by stripping the trailing
'\n' appended to the output of popen("cd %s && pwd -P", p->srcdir).

Replace this cumbersome implementation with a single realpath(3) call
which avoids spawning a shell, reading from the stream with fgets(3),
and final strdup(3).

Reviewed by:		arichardson, kevans
Approved by:		imp
Differential Revision:	https://reviews.freebsd.org/D26734
2021-10-27 09:26:00 +00:00
Kyle Evans d59c5e023d crunch: drop WARNS override
crunchide and crunchgen now build fine with default WARNS
2021-08-19 12:48:00 -05:00
Kyle Evans bfd70233c3 crunchgen: fix remaining issues under WARNS=6
Entirely variables that should be static, save for one 'no previous
declaration' in mkskel.sh.

Reviewed by:	arichardson, imp
Differential Revision:	https://reviews.freebsd.org/D31610
2021-08-19 12:47:48 -05:00
Kyle Evans 7ff87026d6 crunchide: static'ify remaining non-exported functions
Reviewed by:	arichardson, imp
Differential Revision:	https://reviews.freebsd.org/D31609
2021-08-19 12:47:32 -05:00
Kyle Evans dd7c7ff192 crunchide: address complaints from WARNS=6
- One (1) constify
- One (1) argument is unused
- One (1) local shadows a global
- Various globals that should be static

Reviewed by:	arichardson, imp
Differential Revision:	https://reviews.freebsd.org/D31608
2021-08-19 12:47:18 -05:00
Kyle Evans db7f7446b5 crunchgen: sprinkle some const-poisoning around
Reviewed by:	arichardson, imp
Differential Revision:	https://reviews.freebsd.org/D31607
2021-08-19 12:47:08 -05:00
Stefan Eßer 7483b9e4dc Lift scope of buf[] to make it extend to a potential access via *basename
It can be assumed that the contents of the buffer was still allocated and
valid at the point of the out-of-scope access, so there was no security
issue in practice.

Reported by:	Coverity Scan CID 1437697
MFC after:	3 days
2020-12-10 09:31:05 +00:00
Alex Richardson f7ff7baaf6 crunchgen: fix NULL-deref bug introduced in r364647
While porting over the local changes from CheriBSD for upstreaming, I
accidentally committed a broken version of find_entry_point(): we have to
return NULL if the value is not found instead of a value with
ep->name == NULL, since the checks in main were changed to check ep instead
of ep->name for NULL.

This only matters if the crunched tool cannot be found using normal lookup
and one of the fallback paths is used, so it's unlikely to be triggered
in rescue. However, I noticed that one of our CheriBSD test scripts was
failing to run commands under `su` on minimal disk images where all
binaries are hardlinks to a `cheribsdbox` tool generated with crunchgen.

This also updates the bootstrapping check in Makefile.inc1 to bootstrap
crunchgen up to the next version bump.

Reviewed By:	kevans
Differential Revision: https://reviews.freebsd.org/D27474
2020-12-04 15:53:37 +00:00
Kyle Evans 9c7bd4f198 crunchgen: fix MK_AUTO_OBJ logic after r364166
r364166 converted echo -n `/bin/pwd` to a raw pwd invocation, leaving a
trailing newline at the end of path.  This caused a later stat() of it to
erroneously fail and the fallback to MK_AUTO_OBJ=no logic proceeded as
unexpected.

Harry Schmalzbauer bissected the resulting build failure he experienced
(stable/12 host, -HEAD build) down to r365887. This change is mostly
unrelated, except it switches the build to bootstrapped crunchgen - clue!

I then bissected recent crunchgen changes going back a bit since we wouldn't
observe the failure immediately with -CURRENT in most configurations, which
landed me on r364166. After many intense head-scratching minutes and printf
debugging, I realized that the newline was the difference. This is where our
tale ends.

Reported by:	Harry Schmalzbauer, O. Hartmann, Mike Tancsa, kevans
MFC after:	3 days
2020-10-05 20:57:44 +00:00
Adrian Chadd 0dcdda0984 [rcorder] [crunch] Fix C function declarations to include void
This fixes a compile issue under gcc6 which complains about
legacy style C function declarations.

Differential Revision:	https://reviews.freebsd.org/D26504
2020-09-21 17:59:45 +00:00
Kyle Evans fc90521002 crunchgen(8): fix crunched application build with WARNS=6
This was revealed by the rescue build with a patch I'm working on to default
WARNS=6 everywhere. The issues resolved were:

- Missing prototype for _crunched_${ident}_stub in the *_stub.c generated
  bits
- Missing prototype for crunched_main
- Incomplete prototype for _crunched_${ident}_stub in the generated parts of
  crunched_main
- Literal strings in the stub table must drop const qualifier, unless we
  const'ify name
- f field in struct stub didn't have a proper prototype

Most of these issues are minor formalities and easily addressed.

I note that if my patch to eventually raise WARNS for the rescue build
lands, we'll need to bump the __FreeBSD_version requirement for
bootstrapping crunchgen and wipe out the rescue .OBJDIR if it's stale, which
we should be able to detect pretty easily from a couple of the issues that
have been fixed here.

Reviewed by:	arichardson
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D26363
2020-09-10 18:19:45 +00:00
Alex Richardson 50e525e40b Correctly determine the real executable in crunched binaries
This should fix cases like su setting argv[0] to _su for /bin/sh.
Previously cheribsdbox (a crunched tool we use in CheriBSD to reduce the
size of our minimal disk images to allow loading them onto FPGAs without
waiting forever for the transfer) would complain about _su not being
compiled in, but now that we also look at AT_EXECPATH it correctly
invokes the sh tool.

Note: we use use AT_EXECPATH instead of the KERN_PROC_PATHNAME sysctl to get
the crunchgen binary name since it seems like KERN_PROC_PATHNAME just
returns the last cached path for a given hardlink.
When using `su`, instead of invoking /bin/csh this would invoke the last
used hardlink to cheribsdbox. This caused weird test failures when running
tests due to `id` being executed instead of `echo`:

$ id  # id is a hardlink to /bin/cheribsdbox
$ su postgres -c 'echo 1' # su is also a hardlink
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)

Obtained from: CheriBSD

Reviewed By:	emaste, brooks
Differential Revision: https://reviews.freebsd.org/D25998
2020-08-24 09:20:23 +00:00
Alex Richardson b0f558df9f Re-indent crunched_main.c in preparation for D25998 2020-08-24 09:20:18 +00:00
Alex Richardson 0d5e651861 crunchgen: use pwd -P without env
The -P flag is required by POSIX so we don't have to care whether pwd is
a shell builtin or not. This also allows removing pwd from the list of
bootstrap tools since all shells we care about for building have a
builtin pwd command. This effectively reverts r364190.

Suggested By:	rgrimes, jrtc27
2020-08-14 09:45:41 +00:00
Alex Richardson d5c62a6f03 Use env pwd instead of pwd in crunchgen.c
In r364166 I changed /bin/pwd to pwd, but pwd can be shell builtin that
may not correctly return a real path. To ensure that all symlinks are
resolved use `env pwd -P` instead (the -P flag is part of POSIX so
should be supported everywhere).

Reported By:	rgrimes
Suggested By:	jrtc27
2020-08-12 17:27:24 +00:00
Alex Richardson 188d6f4bc6 Fix crunchgen usage of mkstemp()
On Glibc systems mkstemp can only be used once with the same template
string since it will be modified in-place and no longer contain any 'X' chars.
It is fine to reuse the same file here but we need to be explicit and use
open() instead of mkstemp() on the second use.

While touching this file also avoid a hardcoded /bin/pwd since that may not
work when building on non-FreeBSD systems.

Reviewed By:	brooks
Differential Revision: https://reviews.freebsd.org/D25990
2020-08-12 15:49:06 +00:00
Ed Maste cda6f02d43 crunch: remove rsh and rlogin from example config file
rcmds removed in r324351.

Historical references in the README are maintained.  There's a paragraph
describing a "980K crunched 'fixit'" that references rsh and rlogin.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2019-08-13 15:23:14 +00:00
Warner Losh bb0e923848 Remove obsolete RELEASE_CRUNCH
Remove documentation of RELEASE_CRUNCH here. It's obsolete and no longer a good
example.
2019-07-19 20:04:21 +00:00
Eitan Adler 4750b59aca send-pr: wave goodbye
Entering into the world of 12.x we no longer need even the placeholder
for send-pr. It has not done anything for some time.

With Hat: bugmeister
2018-08-19 07:12:35 +00:00
Pedro F. Giffuni 1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified 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.

No functional change intended.
2017-11-27 15:37:16 +00:00
Konstantin Belousov 93b09f581a Remove badsect(8).
Failure modes of the modern (that is, produced in the last 25 years)
hard drives and SSDs made the utility outdated.  Since the kernel
interface to support it was removed in r324853, cut the userspace
remnants as well.

Discussed with:	bde (who does not like the removal)
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2017-11-05 22:00:54 +00:00
Bryan Drewery ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Gordon Tetlow 4572fb3faf Deorbit catman. The tradeoff of disk for performance has long since tipped
in favor of just rendering the manpage instead of relying on pre-formatted
catpages. Note, this does not impede the ability to use existing catpages,
it just removes the utility to generate them.

Reviewed by:	imp, allanjude
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D12317
2017-09-13 16:35:16 +00:00
Ryan Libby e881ec1646 crunchgen: quiet -Wmissing-prototypes
Reviewed by:	emaste (previous version)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D12107
2017-09-07 17:20:47 +00:00
Bjoern A. Zeeb 4a6768e64c Teach crunchide about EM_S390 to make bootstrapping from future
releases easier unless someone will fix the PR properly.

MFC after:	3 days
PR:		215940
2017-01-10 14:40:30 +00:00
Warren Block 5589c6def0 Show that the crunchgen configuration file name is not optional.
PR:		215087
Submitted by:	Iblis Lin <iblis@hs.ntnu.edu.tw>
MFC after:	1 week
Sponsored by:	iXsystems
2017-01-06 18:04:34 +00:00
Ed Maste f513dfd44b crunchide: report explicit error for combined string table
Some tools produce objects with a combined strtab and shstrtab.
These objects are not supported by crunchide since it rewrites the
symtab and strtab to "hide" symbols. This invalidates section header
offsets into a combined strtab/shstrtab.

In the future we could support these objects (by ensuring that we retain
unmodified section name strings in the output .strtab, and then rewriting
each section header's sh_name).

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2016-11-17 18:12:17 +00:00
Ed Maste 69712279cc crunchide: remove obsolete a.out header and comment
crunchide(1) gained ELF support in r39172, and lost the unused a.out
and non-functional ECOFF suport in r281655.

Sponsored by:	The FreeBSD Foundation
2016-11-16 16:39:51 +00:00
Ed Maste 7c10d87b78 crunchgen: do not strip crunched binary (it will be done by install)
Reviewed by:	adrian, imp (earlier)
Differential Revision:	https://reviews.freebsd.org/D2003
2016-09-30 13:16:04 +00:00
Bryan Drewery 5017231ad7 META_MODE/DIRDEPS_BUILD: Fix various issues with crunch builds.
- DIRDEPS_BUILD: Fix crunchgen builds losing their library dependencies
  on a nop-rebuild.
- META_MODE: Fix not rebuilding various crunch.mk targets if their .meta
  files warrant a rebuild.  They were lacking .meta files previously.
  This adds .NOMETA to the crunch objects being used since they are
  already built.  Bmake was forcing a rebuild on them since their
  .meta files were not in the expected place; there is no reason to
  rebuild them.

MFC after:	2 weeks
Sponsored by:	EMC / Isilon Storage Division
2016-09-01 23:21:08 +00:00
Bryan Drewery eb9b07bb77 WITH_AUTO_OBJ: Fix crunchgen builds.
Passing MAKEOBJDIRPREFIX to the main prog build (rescue) would confuse
WITH_AUTO_OBJ and cause it to create a recursed object directory that
then broke the actual prog build.  This is normally not a problem since
we do not call 'make -f prog.mk obj' before building anything in it.

Crunchgen(1) also assumes that if -o is not passed then if an object
directory does not already exist then it should build in the source
directories.  The normal buildworld process will have already ran 'make
obj' in each of the component directories so this is not a problem.
With WITH_AUTO_OBJ though this is not the case.  So we must tell
crunchgen(1) that MK_AUTO_OBJ=yes will create the directory and to not
require it be present before generating its Makefile.

Sponsored by:	EMC / Isilon Storage Division
2016-05-26 23:20:36 +00:00
Bryan Drewery bd18fd57db DIRDEPS_BUILD: Regenerate without local dependencies.
These are no longer needed after the recent 'beforebuild: depend' changes
and hooking DIRDEPS_BUILD into a subset of FAST_DEPEND which supports
skipping 'make depend'.

Sponsored by:	EMC / Isilon Storage Division
2016-02-24 17:20:11 +00:00
Ed Maste c8daf7a00f crunchide: add RISC-V to supported machine types
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2015-12-11 13:55:31 +00:00
Bryan Drewery b99a71b1da Fix rescue build after r284356 with STRIP= by using proper STRIPBIN per build(7).
This was causing the following error:

  rescue
  sh: rescue: not found
  *** [rescue] Error code 127

  make[1]: stopped in /usr/obj/usr/src/rescue/rescue

Sponsored by:	EMC / Isilon Storage Division
2015-07-28 21:39:58 +00:00
Simon J. Gerraty 2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00