Mail Archives: djgpp/2023/01/29/11:27:06
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=to:subject:message-id:date:from:references:in-reply-to:mime-version
|
| :from:to:cc:subject:date:message-id:reply-to;
|
| bh=WwsYTkgiZxZba2caAJXwF35o3w5yB4tycf3RZnTBCic=;
|
| b=gxUhuKwSvuL2RkMhGiayALIzRS8COVyDeowJRal4+dnvFkfVCWUOx8VNbdvGKzrZNu
|
| 0E+cpRTfwr8tI/0BIeKCcIlr+aRY8Qjp76I0F1DyU2YAw4OQQ/to7HK+/1yBCNvhxRlT
|
| aPuxFCfN3BRNTL7D04OrQfVV6m/35YO9JscfRpuvUOIYyX/p8Wyfn2OvhCG+QCLEAJRr
|
| NobQToFE0V+631N2Gv31GGghbt+m/7T/ezZ1ntBkNEf159eIpV0D9n7faqhIi0hdkhVN
|
| R9SNOQKPpA0eecNY+xqndATBDqG/iEecKqNqMDjCpomlQfZom9wxcxg/MMF29OEAu9ly
|
| Tvig==
|
X-Google-DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed;
|
| d=1e100.net; s=20210112;
|
| h=to:subject:message-id:date:from:references:in-reply-to:mime-version
|
| :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
|
| bh=WwsYTkgiZxZba2caAJXwF35o3w5yB4tycf3RZnTBCic=;
|
| b=TNF0C8iteGVi2R4Uh4NEXLIklM9je8v1sBSLinpzO6i9ZiogiDHdaXuvsfKhOwGPiW
|
| 35WC/ssjw2u/GSSbyswj7u52fZ8LnfrgMUDUPaqO4ibH+lwuCfuo6yQzBX6Fh14Yx6iG
|
| WLAiMLqGBmPUUjOoJDdhSV0xqhYS6Zmph1Xdt3eD1yOfiSdoIKAKE/Z+VX02brQPCmA9
|
| r+h1c15Tgs2vBHMWWk2ui/cu4N8MWUnAv3ISnrWvhPeYiHqynk+M44t1iIsCPfuLwO5u
|
| lkUtRdiHR3bKHEQZWuLmjoCT7gqLFmGMgzlVr/2C4oyRDsIgR14eJX15Z9KUYGI+0JMX
|
| uZEQ==
|
X-Gm-Message-State: | AFqh2kpzn87FrLtkXygdabdfVBB3a1OTRqjrjdYQQDU8Ll3Ht1HWJPyp
|
| 56V2/V5ipl5KZttMnQdQkZdk2ZEvP1T+o9i1ah+XAtXw
|
X-Google-Smtp-Source: | AMrXdXv8GwS7wiiLi22BdAgotj5FzuwqSUmx8PHfq09+i4bTMlOZ76+oIOQk2XX7X3wG/wjBZ4aBWbIi5V6dyeEUJjM=
|
X-Received: | by 2002:a05:600c:4ca7:b0:3cf:7b68:631 with SMTP id
|
| g39-20020a05600c4ca700b003cf7b680631mr2228099wmp.55.1675009428554; Sun, 29
|
| Jan 2023 08:23:48 -0800 (PST)
|
MIME-Version: | 1.0
|
In-Reply-To: | <83h6w973ct.fsf@gnu.org>
|
References: | <d67303fd-c302-82cc-bb0d-d1a21640d66f AT gmail DOT com>
|
| <CAA2C=vDYkF13NYPP_EXGMwzrjhLj2vEq68+-uYPfZOXpqWVRfQ AT mail DOT gmail DOT com>
|
| <83r0vd78cu DOT fsf AT gnu DOT org> <CAA2C=vCCYsgtbQ5wsgbS3S4G7N+H5zi5DxCyVZLSkEKrSpifMw AT mail DOT gmail DOT com>
|
| <83o7qh74td DOT fsf AT gnu DOT org> <CAA2C=vDT10ZGfa3Mi2x0syvoT44Q3nfgcMfOwMZF=dM+ruL5OA AT mail DOT gmail DOT com>
|
| <83h6w973ct DOT fsf AT gnu DOT org>
|
From: | "Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
|
Date: | Sun, 29 Jan 2023 19:23:47 +0300
|
Message-ID: | <CAA2C=vCizSbiUAy7j3NXTdfb5OUYGPFO-kojb1XKHTdzvYYoTw@mail.gmail.com>
|
Subject: | Re: [PATCH v3] dxe3gen: invoke ld/as via gcc
|
To: | djgpp AT delorie DOT com
|
Reply-To: | djgpp AT delorie DOT com
|
Errors-To: | nobody AT delorie DOT com
|
X-Mailing-List: | djgpp AT delorie DOT com
|
X-Unsubscribes-To: | listserv AT delorie DOT com
|
>>> If so, what do you suggest to do with
>>> libstdc++, which AFAIU was the original motivation for the change?
>>
>> Aren't all gcc-provided versioned libraries residing in the same dir?
>> My patch just relies on that.
>
> Maybe so, I simply don't know. So I think the code should have a
> comment to that effect.
Updated patch inlined below:
Comment added as suggested, documentation updated, and while loop
reading from pipe removed and reduced to a single fread.
Index: dxe3gen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/dxe/dxe3gen.c,v
retrieving revision 1.27
diff -u -p -r1.27 dxe3gen.c
--- djgpp/src/dxe/dxe3gen.c 28 Jan 2023 14:10:03 -0000 1.27
+++ djgpp/src/dxe/dxe3gen.c 29 Jan 2023 15:55:10 -0000
@@ -19,6 +19,7 @@
otherwise the exit code of GNU ld is returned
*/
+#include <limits.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -193,7 +194,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 +205,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 12
#define NUMBER_OF_ADDITIONAL_LOADED_LIBS 0
#define IS_VALID_CIE(id) ((id) == 0)
@@ -465,6 +466,37 @@ static void process_env(void)
}
+/* Desc: Read libgcc directory from the compiler so that ld can find -lgcc
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: Useful for linking a dxe with gcc-provided libraries. Other gcc-
+ * provided libraries, such as libbtdc++, will be under either the
+ * same directory, or under $DJDIR/lib which we already know where.
+ */
+#ifdef _WIN32
+#define popen _popen
+#define pclose _pclose
+#endif
+static char libgcc_dir[PATH_MAX];
+static void read_libgccdir(void)
+{
+ char *ptr;
+ FILE *p;
+
+ sprintf(libgcc_dir, "%s -print-libgcc-file-name", dxe_cc);
+ p = popen(libgcc_dir,"r");
+ memset(libgcc_dir, 0, sizeof(libgcc_dir));
+ if (p == NULL) return;
+ (void) fread(libgcc_dir, 1, sizeof(libgcc_dir), p);
+ pclose(p);
+ ptr = strrchr(libgcc_dir, '\\');
+ if (!ptr) ptr = strrchr(libgcc_dir, '/');
+ if (ptr) *ptr = '\0';
+ /* else: shouldn't ever happen */
+}
+
/* Desc: process command line args
*
* In : no of arguments, argument list, ptr to store linker args
@@ -481,6 +513,12 @@ static void process_args(int argc, char
fprintf(stderr, "Error: neither DXE_LD_LIBRARY_PATH nor DJDIR are
set in environment\n");
exit(1);
}
+ read_libgccdir();
+ if (!libgcc_dir[0])
+ {
+ fprintf(stderr, "Error: failed determining libgcc directory\n");
+ exit(1);
+ }
new_argv[0] = dxe_ld;
new_argv[1] = "-X";
@@ -490,8 +528,10 @@ static void process_args(int argc, char
new_argv[5] = TEMP_O_FILE;
new_argv[6] = "-L";
new_argv[7] = libdir;
- new_argv[8] = "-T";
- new_argv[9] = dxe_sc;
+ new_argv[8] = "-L";
+ new_argv[9] = libgcc_dir;
+ new_argv[10] = "-T";
+ new_argv[11] = dxe_sc;
if (!strcmp(base_name(argv[0]), "dxegen"))
/* invoked as `dxegen' */
Index: dxegen.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/dxe/dxegen.txi,v
retrieving revision 1.10
diff -u -r1.10 dxegen.txi
--- djgpp/src/dxe/dxegen.txi 28 Jan 2023 14:10:33 -0000 1.10
+++ djgpp/src/dxe/dxegen.txi 29 Jan 2023 15:55:10 -0000
@@ -60,16 +60,16 @@
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.
+environments, and i586-pc-msdosdjgpp-gcc for cross-build environments.
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-as for cross-build environments.
DXE_AR: Archiver name. If not set, defaults to ar for native build
-environments, and i586-pc-msdosdjgpp-ar for cross-build environmlents.
+environments, and i586-pc-msdosdjgpp-ar for cross-build environments.
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-ld 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'
@@ -223,12 +223,8 @@
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
Index: makefile.dxe
===================================================================
RCS file: /cvs/djgpp/djgpp/src/dxe/makefile.dxe,v
retrieving revision 1.3
diff -u -p -r1.3 makefile.dxe
--- djgpp/src/dxe/makefile.dxe 28 Jan 2023 14:10:04 -0000 1.3
+++ djgpp/src/dxe/makefile.dxe 29 Jan 2023 15:55:10 -0000
@@ -10,6 +10,7 @@ CROSS_LD = $(CROSS_PREFIX)ld
CROSS_STRIP = $(CROSS_PREFIX)strip
CC = gcc
+HOST_CC = gcc
all: dxe3gen dxegen dxe3res
@@ -41,7 +42,7 @@ dxe3res: dxe3res.c
$(CC) -O2 -Wall dxe3res.c -o $@
bin2h.exe: ../utils/bin2h.c
- $(CC) ../utils/bin2h.c -o $@
+ $(HOST_CC) ../utils/bin2h.c -o $@
clean:
rm -f *.o *.h bin2h.exe dxegen dxe3gen dxe3res
Index: wc206.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc206.txi,v
retrieving revision 1.17
diff -u -r1.17 wc206.txi
--- djgpp/src/docs/kb/wc206.txi 28 Jan 2023 14:10:03 -0000 1.17
+++ djgpp/src/docs/kb/wc206.txi 29 Jan 2023 15:55:10 -0000
@@ -25,6 +25,10 @@
@command{dxe3gen} now handles extended coff relocations (more than
65535 relocs.
Requires a DJGPP port of binutils-2.22 or newer.)
+@cindex dxe3gen and gcc-provided libraries
+@command{dxe3gen} now automatically locates gcc-provided libraries such as
+@file{libgcc} without additional user effort.
+
@cindex Update of DXE linker script
The dxe linker script @file{dxe.ld} now handles @code{.gnu.linkonce.b.*}
and @code{.bss.*} sections.
- Raw text -