
Currently, object files in libgit.a reference common_exit(), which is contained in common-main.o. However, common-main.o also includes main(), which references cmd_main() in git.o, which in turn depends on all the builtin/*.o objects. We would like to allow external users to link libgit.a without needing to include so many extra objects. Enable this by splitting common_exit() and check_bug_if_BUG() into a new file common-exit.c, and add common-exit.o to LIB_OBJS so that these are included in libgit.a. This split has previously been proposed ([1], [2]) to support fuzz tests and unit tests by avoiding conflicting definitions for main(). However, both of those issues were resolved by other methods of avoiding symbol conflicts. Now we are trying to make libgit.a more self-contained, so hopefully we can revisit this approach. Additionally, move the initialization code out of main() into a new init_git() function in its own file. Include this in libgit.a as well, so that external users can share our setup code without calling our main(). [1] https://lore.kernel.org/git/Yp+wjCPhqieTku3X@google.com/ [2] https://lore.kernel.org/git/20230517-unit-tests-v2-v2-1-21b5b60f4b32@google.com/ Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
27 lines
680 B
C
27 lines
680 B
C
#include "git-compat-util.h"
|
|
#include "trace2.h"
|
|
|
|
static void check_bug_if_BUG(void)
|
|
{
|
|
if (!bug_called_must_BUG)
|
|
return;
|
|
BUG("on exit(): had bug() call(s) in this process without explicit BUG_if_bug()");
|
|
}
|
|
|
|
/* We wrap exit() to call common_exit() in git-compat-util.h */
|
|
int common_exit(const char *file, int line, int code)
|
|
{
|
|
/*
|
|
* For non-POSIX systems: Take the lowest 8 bits of the "code"
|
|
* to e.g. turn -1 into 255. On a POSIX system this is
|
|
* redundant, see exit(3) and wait(2), but as it doesn't harm
|
|
* anything there we don't need to guard this with an "ifdef".
|
|
*/
|
|
code &= 0xff;
|
|
|
|
check_bug_if_BUG();
|
|
trace2_cmd_exit_fl(file, line, code);
|
|
|
|
return code;
|
|
}
|