[botan-devel] msvc build for ARM handhelds - wrong machine file header written?

ToBeKi at gmx.de ToBeKi at gmx.de
Mon Jan 14 03:46:30 EST 2013


Hi all,

tried to compile Botan for ARM handhelds with following command:

configure.py --cc=msvc --cpu=arm --enable-debug -–disable-modules=idea,rc2,rc5,adler32,aes_isa_eng,aont,arc4,bcrypt,benchmark,blowfish,bmw_512,camellia,cascade,cts,dlies,dyn_engine,dyn_load,eax,fpe_fe1,gost_28147,gost_3410,gost_3411,has160,hres_timer,kasumi,kdf1,kdf2,keccak,lion,lubyrack,mars,md2,md4,md4_x86_32,mgf1,misty1,noekeon,noekeon_simd,nr,ofb,openpgp,par_hash,passhash9,pbes1,pbes2,pbkdf1,pbkdf2,pgps2k,pk_filts,prf_ssl3,prf_tls,prf_x942,rc2,rfc3394,rmd128,rmd160,rw,safer,salsa20,selftest,serpent,serpent_simd,serpent_x86_32,simd,simd_engine,simd_scalar,skein,skipjack,square,srp6,ssl3mac,tea,tiger,tss,turing,twofish,whirlpool,wid_wake,x919_mac,x931_rng,xtea,xtea_simd,xts

Linking against the produced libraries produced the following error:

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'ARM'	botan.lib	TestBotan

Testing the created botan DLL with following code shows that a x86 machine file header was written.
Can someone point me out what to configure for a correct ARM build (with arm machine file header).

//------------------------------------------------------------------
//  GetMachineType.cpp - Get MachineType of Given Binary File
//------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winnt.h>

// It’s done as vc++ 6.0 wint.h does not have the IMAGE_FILE_MACHINE_AMD64 declaration
#ifndef IMAGE_FILE_MACHINE_AMD64
#define IMAGE_FILE_MACHINE_AMD64 0x8664
#endif

//------------------------------------------------------------------
LPVOID MapFile(char *szFileName, HANDLE *hFile, HANDLE *hMap);
DWORD  GetMachineType(LPBYTE pIn);
void   UnmapFile(HANDLE hFile, HANDLE hMap, LPVOID pMem);

// Start of the application………

int main(int)
{
   HANDLE hFile, hMap;
   LPVOID pIn;
   DWORD  Stat;
   
   char *pszPathname = "D:\\workspace\\CheckMachineType\\TestBinaries\\botan_arm.lib";                               // Tbuild

   // Make a (memory) file mapping for the binary
   if ((pIn = MapFile(pszPathname, &hFile, &hMap)) == NULL) {
      printf("Error: couldn't open or map %s\n", pszPathname);
      return ERROR_OPEN_FAILED;
   }

   if ((Stat = GetMachineType((LPBYTE)pIn)) != NO_ERROR) {

      switch(Stat)
      {
      case IMAGE_FILE_MACHINE_I386:
         printf("MachineType of %s is = %s\n", pszPathname, "I386 (x86)");
         break;

      case IMAGE_FILE_MACHINE_IA64:
         printf("MachineType of %s is = %s\n", pszPathname, "IA64 (Intel IPF)");
         break;

      case IMAGE_FILE_MACHINE_AMD64:
         printf("MachineType of %s is = %s\n", pszPathname, "AMD64 (x64)");
         break;

      case IMAGE_FILE_MACHINE_ARM:
         printf("MachineType of %s is = %s\n", pszPathname, "ARM (x64)");
         break;

      default:
         printf("Unknown MachineType\n");
      }
   }


   // Unmap it, memory changes will be written to the image
   UnmapFile(hFile, hMap, pIn);

   return NO_ERROR;
}

// Get the memory mapping of windows binary file …..
LPVOID MapFile(char *szFile, HANDLE *hFile, HANDLE *hMap)
{
   // Create a memory mapping for the specified file
   DWORD Size;

   *hFile = *hMap = NULL;
   if ((*hFile = CreateFile(szFile, GENERIC_READ | GENERIC_WRITE,
                            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) ==
                            INVALID_HANDLE_VALUE) {
      return NULL;
   }

   Size = GetFileSize(*hFile, NULL);

   if ((*hMap = CreateFileMapping(*hFile, NULL, PAGE_READWRITE, 0,
      Size, NULL)) == NULL) {
         CloseHandle(hFile);
         return NULL;
   }
   return MapViewOfFile(*hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
}

// This will return dword machine type of the binary…..
DWORD GetMachineType(LPBYTE pIn)
{
   long                  lPeStart;
   IMAGE_NT_HEADERS     *pNtHdr;

   // See where the PE image header is located
   if ((((IMAGE_DOS_HEADER *)pIn)->e_magic != IMAGE_DOS_SIGNATURE) || ((lPeStart = ((IMAGE_DOS_HEADER *)pIn)->e_lfanew) == 0L)) 
   {
         return ERROR_BAD_EXE_FORMAT;
   };

   pNtHdr = (IMAGE_NT_HEADERS *)(pIn + lPeStart);

   if(pNtHdr->FileHeader.Machine != 0 )
   {
      return pNtHdr->FileHeader.Machine;
   }

   return NO_ERROR;
}

// Unload mapped memory…… cleanup …!!!!
void UnmapFile(HANDLE hFile, HANDLE hMap, LPVOID pMem)
{
   if (pMem != NULL)
      UnmapViewOfFile(pMem);

   if (hMap != NULL)
      CloseHandle(hMap);

   if (hFile != NULL)
      CloseHandle(hFile);

   return ;
}






More information about the botan-devel mailing list