www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2023/01/28/11:20:20

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
Received-SPF: neutral (johanna4.inet.fi: domain iki.fi is neutral about
designating 84.248.104.250 as permitted sender) identity=mailfrom;
receiver=johanna4.inet.fi; client-ip=84.248.104.250;
envelope-from=andris DOT pavenis AT iki DOT fi; helo=[192.168.1.10];
Message-ID: <54690cf9-1ba6-acda-de67-c08071fbb5d7@iki.fi>
Date: Sat, 28 Jan 2023 18:17:02 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Subject: Re: Linking DXE3 with libraries
To: djgpp AT delorie DOT com
References: <496da509-6d4f-88a1-e94a-6c330a915f05 AT iki DOT fi>
<bb48230b-8090-b8d9-a108-8c90820b40e3 AT gmail DOT com>
From: "Andris Pavenis (andris DOT pavenis AT iki DOT fi) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
In-Reply-To: <bb48230b-8090-b8d9-a108-8c90820b40e3@gmail.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

On 1/28/23 13:28, Frank Sapone (emoaddict15 AT gmail DOT com) [via djgpp AT delorie DOT com] wrote:
> Good Morning Andris,
>
>> - DXE loader has no way to found symbols of running executable (which requests to load DXE) 
>> unless one tells where they are located
>>
> Correct, you need a DXE_EXPORT_TABLE with DXE_EXPORT(func/var) to resolve at run time.  See 
> https://bitbucket.org/neozeed/q2dos/src/master/dos/dxe.c for an example if interested.
>> - linking DXE directly with libraries (like libstdcxx.a or libc.a) will cause duplicate copy of 
>> symbols. That is going to cause problems when library have global state. I have seen similar 
>> problems, which have often caused crash of program) for example in Linux, when direct of 
>> indirect dependencies causes 2 different versions of shared library to be loaded:
> I'm not quite sure how it works exactly, but with C we just resolve everything like above, which 
> seems to be the correct way. With C++ things are trickier and we have to do -lstdcxx -lgcc or we 
> get mangled names that can't even be exported.

The following could work (I only tried under Linux, so for native DJGPP and/or other libraries one 
should modify script):

[andris AT ap dxe]$ cat mk_lib_export_table.sh
#! /bin/sh

i686-pc-msdosdjgpp-nm --extern-only /usr/i686-pc-msdosdjgpp/lib/libstdc++.a |\
awk '/^[0-9A-H]/ && ($2 == "W" || $2 == "T") { print $3 }' | sort | uniq |\
sed -e 's/^_//' >symbols.tmp

(
    echo "#include <sys/dxe.h>"
    echo ""
    awk '{ print "extern void ", $1, "();"}' symbols.tmp
    echo ""
    echo "DXE_EXPORT_TABLE (exported_symbols)"
    awk '{print "  DXE_EXPORT(",$1,")"}' symbols.tmp
    echo "DXE_EXPORT_END"
    echo ""
    echo "int main() { return 0; }"
) | i686-pc-msdosdjgpp-gcc -v -O0 -fno-builtin -x c - -l stdc++


Only added main() to avoid having linker error.

Also linked executable to verify that symbols are extracted correctly.

One can there put code to register generated export table instead.


I only tried gcc-12.2.0.

Output of script is given below

Andris


[andris AT ap dxe]$ ./mk_lib_export_table.sh
Using built-in specs.
COLLECT_GCC=i686-pc-msdosdjgpp-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/lto-wrapper
Kohde: i686-pc-msdosdjgpp
Configured with: ../gcc-12.2.0/configure --prefix=/usr --libexecdir=/usr/lib 
--target=i686-pc-msdosdjgpp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-shared 
--enable-static --enable-th
reads=no --with-system-zlib --with-isl --enable-lto --disable-libgomp --disable-multilib 
--enable-checking=release --disable-libstdcxx-pch --enable-libstdcxx-filesystem-ts 
--disable-install-libi
berty
Säiemalli: single
Supported LTO compression algorithms: zlib zstd
gcc-versio 12.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-O0' '-fno-builtin' '-mtune=generic' '-march=pentiumpro' '-dumpdir' 'a-'
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/cc1 -quiet -v -remap - -quiet -dumpdir a- -dumpbase - 
-mtune=generic -march=pentiumpro -O0 -version -fno-builtin -o /tmp/cchC3Spt.s
GNU C17 (GCC) versio 12.2.0 (i686-pc-msdosdjgpp)
        käännetty GNU C:n versiolla 12.1.1 20220730, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC 
version 1.2.1, isl version isl-0.25-GMP

warning: MPFR-otsakeversio 4.1.0-p13 eroaa kirjastoversiosta 4.1.1-p1.
warning: MPC-otsakeversio 1.2.1 eroaa kirjastoversiosta 1.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
jätetään puuttuva hakemisto ”/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/include-fixed” huomiotta
#include "..." -haku alkaa täältä:
#include <...> -haku alkaa täältä:
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/include
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/sys-include
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/include
Hakulistan loppu.
GNU C17 (GCC) versio 12.2.0 (i686-pc-msdosdjgpp)
        käännetty GNU C:n versiolla 12.1.1 20220730, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC 
version 1.2.1, isl version isl-0.25-GMP

warning: MPFR-otsakeversio 4.1.0-p13 eroaa kirjastoversiosta 4.1.1-p1.
warning: MPC-otsakeversio 1.2.1 eroaa kirjastoversiosta 1.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 80ce3899c685b09c12b70d8ca8f6fbac
COLLECT_GCC_OPTIONS='-v' '-O0' '-fno-builtin' '-mtune=generic' '-march=pentiumpro' '-dumpdir' 'a-'
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/bin/as -v -o /tmp/ccIgzJio.o 
/tmp/cchC3Spt.s
GNU assembler version 2.34 (i686-pc-msdosdjgpp) using BFD version (GNU Binutils) 2.34
COMPILER_PATH=/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/:/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/:/usr/lib/gcc/i686-pc-msdosdjgpp/:/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/:/usr/lib/gcc/i686-pc-msdosd
jgpp/:/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/bin/
LIBRARY_PATH=/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/:/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/lib/ 

COLLECT_GCC_OPTIONS='-v' '-O0' '-fno-builtin' '-mtune=generic' '-march=pentiumpro' '-dumpdir' 'a.'
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/collect2 -plugin 
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/liblto_plugin.so 
-plugin-opt=/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/lto-wrapper -plugin-opt=-freso
lution=/tmp/cc8Rf9cH.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc 
-plugin-opt=-pass-through=-lgcc 
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/lib/c
rt0.o -L/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0 
-L/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/lib /tmp/ccIgzJio.o 
-lstdc++ -lgcc -lc -lgcc
COLLECT_GCC_OPTIONS='-v' '-O0' '-fno-builtin' '-mtune=generic' '-march=pentiumpro' '-dumpdir' 'a.'
/usr/lib/gcc/i686-pc-msdosdjgpp/12.2.0/../../../../i686-pc-msdosdjgpp/bin/stubify -v a.out
stubify for djgpp V2.X executables, Copyright (C) 1995-2003 DJ Delorie
stubify: a.out -> a.000 -> a.exe



- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019