Link with uplink module
authorTanzinul Islam <tanzinul.islam@gmail.com>
Sun, 13 Dec 2020 18:04:43 +0000 (18:04 +0000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 19 Apr 2021 09:05:55 +0000 (11:05 +0200)
The Clang-based `bcc32c.exe` expects AT&T syntax for inline assembly.
References:
 - http://docwiki.embarcadero.com/RADStudio/Sydney/en/Differences_Between_Clang-enhanced_C%2B%2B_Compilers_and_Previous-Generation_C%2B%2B_Compilers#Inline_Assembly
 - https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
 - https://sourceware.org/binutils/docs/as/i386_002dVariations.html

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13540)

Configurations/50-cppbuilder.conf
crypto/bio/bss_file.c
ms/applink.c
ms/uplink.c

index b604e12d09c315c2e24aa300a50a172fc6e3e896..0b3b70db92cf7d012e06156a863edf84a06ba281 100644 (file)
@@ -51,5 +51,6 @@ my %targets = (
         dso_scheme       => "win32",
         shared_defflag   => '',
         perl_platform    => 'Windows::cppbuilder',
+        uplink_arch      => 'common',
     }
 );
index 981a5e7b59ffa0b307aa4de2ccb8c24950ef55ac..41c3a596659d61751713ab6c52044ee30e1b1adf 100644 (file)
@@ -216,7 +216,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
 #   define _IOB_ENTRIES 20
 #  endif
         /* Safety net to catch purely internal BIO_set_fp calls */
-#  if defined(_MSC_VER) && _MSC_VER>=1900
+#  if (defined(_MSC_VER) && _MSC_VER>=1900) || defined(__BORLANDC__)
         if (ptr == stdin || ptr == stdout || ptr == stderr)
             BIO_clear_flags(b, BIO_FLAGS_UPLINK_INTERNAL);
 #  elif defined(_IOB_ENTRIES)
index d19966a33ed8cdcaad52e473401be2195b543258..2cf3a92f182a27babe712af4c159c2a4d9cfa9bb 100644 (file)
 # include <io.h>
 # include <fcntl.h>
 
+# ifdef __BORLANDC__
+   /* _lseek in <io.h> is a function-like macro so we can't take its address */
+#  undef _lseek
+#  define _lseek lseek
+# endif
+
 static void *app_stdin(void)
 {
     return stdin;
index 8c61a7ed1d70b7b069c71140f92f1fed5f870adb..f924eb3e58e8123d9838d99fbabb4bbbd5e19d1b 100644 (file)
@@ -99,14 +99,29 @@ void OPENSSL_Uplink(volatile void **table, int index)
     table[index] = func;
 }
 
-#if defined(_MSC_VER) && defined(_M_IX86)
-# define LAZY(i)         \
+#if (defined(_MSC_VER) || defined(__BORLANDC__)) && defined(_M_IX86)
+# if defined(_MSC_VER)
+#  define LAZY(i)         \
 __declspec(naked) static void lazy##i (void) {  \
         _asm    push i                          \
         _asm    push OFFSET OPENSSL_UplinkTable \
         _asm    call OPENSSL_Uplink             \
         _asm    add  esp,8                      \
         _asm    jmp  OPENSSL_UplinkTable+4*i    }
+# elif defined(__BORLANDC__) && defined(__clang__)
+void *OPENSSL_UplinkTable[26]; /* C++Builder requires declaration before use */
+#  define LAZY(i)         \
+__declspec(naked) static void lazy##i (void) { \
+    __asm__("pushl $" #i "; "                  \
+            "pushl %0; "                       \
+            "call  %P1; "                      \
+            "addl  $8, %%esp; "                \
+            "jmp   *%2 "                       \
+            : /* no outputs */                 \
+            : "i" (OPENSSL_UplinkTable),       \
+              "i" (OPENSSL_Uplink),            \
+              "m" (OPENSSL_UplinkTable[i]));   }
+# endif
 
 # if APPLINK_MAX>25
 #  error "Add more stubs..."