X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=y3caTBYMQWTXimoMC2nj91QYqfae14Uxs9GZE8/ziQE=; b=ZJ9PmTHSZomCjNLNAsrzQXG28MwQTyRxQoN6TyGPVyCSx+f5UCJVgr6wUkqwPz55WE BJEbEsJoe8U3xHk51pJ1nZrE6qalHOLeTIv07/2j1lirqDEvOEcrF0tZbBU6IfahO/gG WnAsujbswKs2y/uUTcAGSIYe5m4Z1dO5moQjWgQeSuFViGG+z4HH6T/4cNDati//T8cl OOqsNRRIq9XVSKKAZ0cw41OWqbHtb9U82igRMTZsW337sfRmwvJRdbtnfdbjWA03rb42 HI0G1UNT+SehtDUY/8Lwenv2Ok6RNsCi9Jq05GTKEb3G2tdloWU9gtpfLSKyycJPwV7v snXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=y3caTBYMQWTXimoMC2nj91QYqfae14Uxs9GZE8/ziQE=; b=eFnSjPT0EZSrJJSlgAFPFeU/PU4XsWxM1dcX7rxu7GSO8xulPwyesrCt8c3SCzdlEB y5CkEWfev8WK15DxYlhJnkg2H/2KFWqKgQfpeZhmqNnI/GXI13whOfxh1hFJg44NcuF/ 6Y2yxvMc9eTi4ZU9xYh1qH8/0Q8x6tPOqem4UQTqnstw54E0vF8kDDEMTCYDOl5Mz5av XGu7EHSDa20pTOJUsPMYkeEDwIsH+A2yXSEcrVvERs6ngi7G230m5ziRGdCXAich107u kT46utKrJ4Y03sLCkCmONshCXjCZ4m4BaSR3IQLq5ziPhhPgr1YoJ8GdGCGaz34FFala 2YMA== X-Gm-Message-State: AO0yUKUmH5LTImK9W+P5GgebUAZRX9pwLJz3MNZpMEyg0+gvUUyiKnc9 ENV6vEy+1Xb9TjSGN26TSdU2zw9v+uYh5Q== X-Google-Smtp-Source: AK7set9xjjXEJqKojGObtgLfPNZBGmzMe1VW6u2fUiwHRHCkv5PqvusFHAHRNuq01mcXba6JCSG84w== X-Received: by 2002:a17:906:6592:b0:883:3299:91c8 with SMTP id x18-20020a170906659200b00883329991c8mr4427378ejn.55.1674943771154; Sat, 28 Jan 2023 14:09:31 -0800 (PST) Message-ID: Date: Sat, 28 Jan 2023 23:09:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: djgpp AT delorie DOT com From: "J.W. Jagersma (jwjagersma AT gmail DOT com) [via djgpp AT delorie DOT com]" Subject: [PATCH v3] dxe3gen: invoke ld/as via gcc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Posting this in a new thread since the other became way too long. This applies to current cvs, and should address all raised concerns. I additionally noticed and fixed a small inconsistency in the -h text, as linker options are now wrapped via -Wl. diff --git a/src/dxe/dxe3gen.c b/src/dxe/dxe3gen.c index a61d1a1e..81b5d447 100644 --- a/src/dxe/dxe3gen.c +++ b/src/dxe/dxe3gen.c @@ -170,15 +170,9 @@ #ifndef DXE_CC #define DXE_CC "gcc" #endif -#ifndef DXE_AS -#define DXE_AS "as" -#endif #ifndef DXE_AR #define DXE_AR "ar" #endif -#ifndef DXE_LD -#define DXE_LD "ld" -#endif #ifndef DXE_SC #define DXE_SC "dxe.ld" #endif @@ -193,7 +187,7 @@ #include "../../include/sys/dxe.h" #include "../../include/coff.h" -#define VERSION "1.0.4" +#define VERSION "1.0.5" #define TEMP_BASE "dxe_tmp" /* 7 chars, 1 char suffix */ #define TEMP_O_FILE TEMP_BASE".o" @@ -204,7 +198,7 @@ #define IS_SLASH(path) (((path) == '/') || ((path) == '\\')) #define IS_DIR_SEPARATOR(path) (IS_SLASH(path) || ((path) == ':')) -#define NUMBER_OF_LINKER_ARGS 10 +#define NUMBER_OF_LINKER_ARGS 7 #define NUMBER_OF_ADDITIONAL_LOADED_LIBS 0 #define IS_VALID_CIE(id) ((id) == 0) @@ -314,9 +308,7 @@ static struct static char *libdir; /* build tools */ static char *dxe_cc; /* default: "gcc" */ -static char *dxe_as; /* default: "as" */ static char *dxe_ar; /* default: "ar" */ -static char *dxe_ld; /* default: "ld" */ /* linker script */ static char *dxe_sc; /* default: "dxe.ld" */ @@ -353,6 +345,7 @@ static void exit_cleanup(void) { remove(TEMP_O_FILE); remove(TEMP_S_FILE); + remove(TEMP_BASE".exe"); /* produced by stubify */ } @@ -425,7 +418,7 @@ static void display_help(void) printf("--show-dep\tShow dependencies for specified module\n"); printf("--show-exp\tShow symbols exported by the DXE module\n"); printf("--show-unres\tShow unresolved symbols in the DXE module\n"); - printf("[ld-options]\tAny other options are passed unchanged to ld\n\n"); + printf("[ld-options]\tAny other options are passed via -Wl to the linker\n\n"); printf("-1\t\tSwitch into legacy mode (disables all other options)\n\n"); printf("You should provide appropriate environment at load-time for unresolved modules.\n"); exit(-1); @@ -445,9 +438,7 @@ static void process_env(void) const char *e; dxe_cc = (e = getenv("DXE_CC")) ? strdup(e) : strdup(DXE_CC); - dxe_as = (e = getenv("DXE_AS")) ? strdup(e) : strdup(DXE_AS); dxe_ar = (e = getenv("DXE_AR")) ? strdup(e) : strdup(DXE_AR); - dxe_ld = (e = getenv("DXE_LD")) ? strdup(e) : strdup(DXE_LD); dxe_sc = (e = getenv("DXE_SC")) ? strdup(e) : strdup(DXE_SC); if ((e = getenv("DXE_LD_LIBRARY_PATH"))) @@ -476,23 +467,22 @@ static void process_args(int argc, char *argv[], const char *new_argv[]) { int i, new_argc = NUMBER_OF_LINKER_ARGS; - if (!libdir) + new_argv[0] = dxe_cc; + new_argv[1] = "-nostdlib"; + new_argv[2] = "-Wl,-X,-S,-r"; + new_argv[3] = "-o"; + new_argv[4] = TEMP_O_FILE; + new_argv[5] = "-T"; + new_argv[6] = dxe_sc; + + if (libdir) { - fprintf(stderr, "Error: neither DXE_LD_LIBRARY_PATH nor DJDIR are set in environment\n"); - exit(1); + /* For compatibility with version 1.0.4 and earlier, also search + $DXE_LD_LIBRARY_PATH or $DJDIR/lib, if set. */ + new_argv[new_argc++] = "-L"; + new_argv[new_argc++] = libdir; } - new_argv[0] = dxe_ld; - new_argv[1] = "-X"; - new_argv[2] = "-S"; - new_argv[3] = "-r"; - new_argv[4] = "-o"; - new_argv[5] = TEMP_O_FILE; - new_argv[6] = "-L"; - new_argv[7] = libdir; - new_argv[8] = "-T"; - new_argv[9] = dxe_sc; - if (!strcmp(base_name(argv[0]), "dxegen")) /* invoked as `dxegen' */ opt.legacy = TRUE; @@ -588,13 +578,19 @@ static void process_args(int argc, char *argv[], const char *new_argv[]) else { char *dot = strrchr(argv[i], '.'); - new_argv[new_argc++] = argv[i]; if (dot) { if (!strcasecmp(dot, ".o") || !strcasecmp(dot, ".a")) opt.objcount++; else if (!strcasecmp(dot, ".dxe") || !strcasecmp(dot, ".so")) opt.dxefile = argv[i]; + new_argv[new_argc++] = argv[i]; + } + else + { + char *arg = (char *)malloc(strlen(argv[i]) + 5U); + sprintf(arg, "-Wl,%s", argv[i]); + new_argv[new_argc++] = arg; } } } @@ -1475,8 +1471,8 @@ static int make_implib(void) /* We already have what to clean up */ atexit(exit_cleanup); - /* Allright, now run the assembler on the resulting file */ - sprintf(cmdbuf, "%s -o %s %s", dxe_as, TEMP_O_FILE, TEMP_S_FILE); + /* Alright, now run gcc to assemble the resulting file */ + sprintf(cmdbuf, "%s -c -o %s %s", dxe_cc, TEMP_O_FILE, TEMP_S_FILE); if ((rv = system(cmdbuf)) != 0) { if (rv == -1) @@ -1565,11 +1561,13 @@ int main(int argc, char **argv) int i; int rv; const char **new_argv; + size_t libdir_argc; progname = argv[0]; - /* Prepare the command line for ld */ - new_argv = (const char **)malloc((argc - 1 + NUMBER_OF_LINKER_ARGS + NUMBER_OF_ADDITIONAL_LOADED_LIBS + 2 + 1) * sizeof(char *)); process_env(); + /* Prepare the command line for ld */ + libdir_argc = libdir ? 2 : 0; + new_argv = (const char **)malloc((argc - 1 + libdir_argc + NUMBER_OF_LINKER_ARGS + NUMBER_OF_ADDITIONAL_LOADED_LIBS + 2 + 1) * sizeof(char *)); process_args(argc, argv, new_argv); if (opt.showdep || opt.showexp || opt.showunres) diff --git a/src/dxe/dxegen.txi b/src/dxe/dxegen.txi index b64afe47..20bfb853 100644 --- a/src/dxe/dxegen.txi +++ b/src/dxe/dxegen.txi @@ -54,25 +54,20 @@ Usage: @kbd{dxe3gen [-o output.dxe] [options] [object-files] [ld-options]} --show-dep Show dependencies for specified module --show-exp Show symbols exported by the DXE module --show-unres Show unresolved symbols in the DXE module -[ld-options] Any other options are passed unchanged to ld +[ld-options] Any other options are passed via -Wl to the linker dxe3gen responds to the following environment variables: DXE_CC: C compiler name. If not set, defaults to gcc for native build -environments, and i586-pc-msdosdjgpp-gcc for cross-build environmlents. - -DXE_AS: Assembler name. If not set, defaults to as for native build -environments, and i586-pc-msdosdjgpp-as for cross-build environmlents. +environments, and i586-pc-msdosdjgpp-gcc for cross-build environments. +This is used to invoke the linker and assembler. DXE_AR: Archiver name. If not set, defaults to ar for native build -environments, and i586-pc-msdosdjgpp-ar for cross-build environmlents. - -DXE_LD: Linker name. If not set, defaults to ld for native build -environments, and i586-pc-msdosdjgpp-ld for cross-build environmlents. +environments, and i586-pc-msdosdjgpp-ar for cross-build environments. DXE_SC: Path to linker script name. If not set, defaults to dxe.ld. -Passed internally to ld, like 'ld -T dxe.ld' +Passed internally to the linker, like 'gcc -T dxe.ld' @end example @command{dxe3gen} is a utility which allows you to create files which contain @@ -218,17 +213,7 @@ symbols are nothing but wrappers to @code{dlopen}. The worst case is when the module and so on. As a workaround, keep such names unexported by filtering exported names through @kbd{-E} option. -@item -Linking to gcc-provided libraries like @file{libgcc} might need special care, -because the linker has no idea where @file{libgcc.a} actually is. A solution -to that when using a makefile is, retrieving the libgcc directory and -using it with @option{-L} before @option{-lgcc}: @end itemize -@example -LIBGCCDIR = $(dir $(shell $(CC) -print-libgcc-file-name)) -my.dxe: - dxe3gen -o my.dxe -E _sym -U $(OBJS) -L$(LIBGCCDIR) -lgcc -@end example -*- The best way is to leave the symbols unresolved and resolve them at runtime. To tell @command{dxe3gen} to not fail on unresolved symbols, add the diff --git a/src/dxe/makefile b/src/dxe/makefile index cf715867..6bdff8ba 100644 --- a/src/dxe/makefile +++ b/src/dxe/makefile @@ -34,7 +34,7 @@ $(BIN)/dxe3res.exe : $(C) dxe3res.o $(L) CROSS_CC = $(word 1,$(CROSS_GCC)) $(HOSTBIN)/dxegen.exe : dxe3gen.c init1.h init2.h init3.h init4.h init5.h fini1.h fini2.h fini3.h fini4.h fini5.h - $(GCC) -DDXE_LD=\"$(CROSS_LD)\" -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" -DDXE_AS=\"$(CROSS_AS)\" dxe3gen.c -o $@ + $(GCC) -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" dxe3gen.c -o $@ clean :: @-$(MISC) rm *.o *.h $(HOSTBIN)/dxegen.exe diff --git a/src/dxe/makefile.dxe b/src/dxe/makefile.dxe index f52323e1..d2cd7c4a 100644 --- a/src/dxe/makefile.dxe +++ b/src/dxe/makefile.dxe @@ -32,7 +32,7 @@ fini4.h: fini4.o bin2h.exe fini5.h: fini5.o bin2h.exe dxe3gen: dxe3gen.c init1.h init2.h init3.h init4.h init5.h fini1.h fini2.h fini3.h fini4.h fini5.h - $(CC) -O2 -Wall -DDXE_LD=\"$(CROSS_LD)\" -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" -DDXE_AS=\"$(CROSS_AS)\" dxe3gen.c -o $@ + $(CC) -O2 -Wall -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" dxe3gen.c -o $@ dxegen: dxe3gen ln -s dxe3gen dxegen