2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Small utility functions for winebuild
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-11-06 21:57:11 +01:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
#include <assert.h>
|
2000-06-23 22:15:35 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-09-19 17:24:13 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2009-08-14 13:22:26 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
2000-06-23 22:15:35 +02:00
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
|
2005-09-19 17:24:13 +02:00
|
|
|
#define MAX_TMP_FILES 8
|
|
|
|
static const char *tmp_files[MAX_TMP_FILES];
|
|
|
|
static unsigned int nb_tmp_files;
|
|
|
|
|
2008-12-08 17:07:50 +01:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum target_cpu cpu;
|
|
|
|
} cpu_names[] =
|
|
|
|
{
|
|
|
|
{ "i386", CPU_x86 },
|
|
|
|
{ "i486", CPU_x86 },
|
|
|
|
{ "i586", CPU_x86 },
|
|
|
|
{ "i686", CPU_x86 },
|
|
|
|
{ "i786", CPU_x86 },
|
|
|
|
{ "x86_64", CPU_x86_64 },
|
|
|
|
{ "sparc", CPU_SPARC },
|
|
|
|
{ "alpha", CPU_ALPHA },
|
2009-11-17 20:20:48 +01:00
|
|
|
{ "powerpc", CPU_POWERPC },
|
|
|
|
{ "arm", CPU_ARM }
|
2008-12-08 17:07:50 +01:00
|
|
|
};
|
|
|
|
|
2005-09-19 17:24:13 +02:00
|
|
|
/* atexit handler to clean tmp files */
|
|
|
|
static void cleanup_tmp_files(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < MAX_TMP_FILES; i++) if (tmp_files[i]) unlink( tmp_files[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
void *xmalloc (size_t size)
|
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
|
|
|
|
res = malloc (size ? size : 1);
|
|
|
|
if (res == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Virtual memory exhausted.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *xrealloc (void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *res = realloc (ptr, size);
|
2005-03-18 15:03:38 +01:00
|
|
|
if (size && res == NULL)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
|
|
|
fprintf (stderr, "Virtual memory exhausted.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *xstrdup( const char *str )
|
|
|
|
{
|
|
|
|
char *res = strdup( str );
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Virtual memory exhausted.\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *strupper(char *s)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
for (p = s; *p; p++) *p = toupper(*p);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2005-05-06 17:54:41 +02:00
|
|
|
int strendswith(const char* str, const char* end)
|
|
|
|
{
|
|
|
|
int l = strlen(str);
|
|
|
|
int m = strlen(end);
|
|
|
|
return l >= m && strcmp(str + l - m, end) == 0;
|
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
void fatal_error( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
va_start( valist, msg );
|
2000-09-28 01:40:43 +02:00
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (current_line)
|
|
|
|
fprintf( stderr, "%d:", current_line );
|
|
|
|
fputc( ' ', stderr );
|
|
|
|
}
|
2004-03-25 01:40:52 +01:00
|
|
|
else fprintf( stderr, "winebuild: " );
|
2000-06-23 22:15:35 +02:00
|
|
|
vfprintf( stderr, msg, valist );
|
|
|
|
va_end( valist );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-10-23 23:33:06 +02:00
|
|
|
void fatal_perror( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
va_start( valist, msg );
|
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (current_line)
|
|
|
|
fprintf( stderr, "%d:", current_line );
|
|
|
|
fputc( ' ', stderr );
|
|
|
|
}
|
|
|
|
vfprintf( stderr, msg, valist );
|
|
|
|
perror( " " );
|
|
|
|
va_end( valist );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-03-18 06:30:54 +01:00
|
|
|
void error( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
va_start( valist, msg );
|
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (current_line)
|
|
|
|
fprintf( stderr, "%d:", current_line );
|
|
|
|
fputc( ' ', stderr );
|
|
|
|
}
|
|
|
|
vfprintf( stderr, msg, valist );
|
|
|
|
va_end( valist );
|
|
|
|
nb_errors++;
|
|
|
|
}
|
|
|
|
|
2000-09-28 01:40:43 +02:00
|
|
|
void warning( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
2002-03-21 02:38:53 +01:00
|
|
|
|
|
|
|
if (!display_warnings) return;
|
2000-09-28 01:40:43 +02:00
|
|
|
va_start( valist, msg );
|
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (current_line)
|
|
|
|
fprintf( stderr, "%d:", current_line );
|
|
|
|
fputc( ' ', stderr );
|
|
|
|
}
|
|
|
|
fprintf( stderr, "warning: " );
|
|
|
|
vfprintf( stderr, msg, valist );
|
|
|
|
va_end( valist );
|
|
|
|
}
|
|
|
|
|
2006-08-11 20:41:29 +02:00
|
|
|
int output( const char *format, ... )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start( valist, format );
|
|
|
|
ret = vfprintf( output_file, format, valist );
|
|
|
|
va_end( valist );
|
|
|
|
if (ret < 0) fatal_perror( "Output error" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-02-04 19:37:13 +01:00
|
|
|
/* find a build tool in the path, trying the various names */
|
2009-08-27 13:35:46 +02:00
|
|
|
static char *find_tool( const char * const *names )
|
2009-02-04 19:37:13 +01:00
|
|
|
{
|
|
|
|
static char **dirs;
|
|
|
|
static unsigned int count, maxlen;
|
|
|
|
|
|
|
|
char *p, *file;
|
|
|
|
unsigned int i, len;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (!dirs)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
/* split the path in directories */
|
|
|
|
|
|
|
|
if (!getenv( "PATH" )) return NULL;
|
|
|
|
path = xstrdup( getenv( "PATH" ));
|
|
|
|
for (p = path, count = 2; *p; p++) if (*p == ':') count++;
|
|
|
|
dirs = xmalloc( count * sizeof(*dirs) );
|
|
|
|
count = 0;
|
|
|
|
dirs[count++] = p = path;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
while (*p && *p != ':') p++;
|
|
|
|
if (!*p) break;
|
|
|
|
*p++ = 0;
|
|
|
|
dirs[count++] = p;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*names)
|
|
|
|
{
|
2009-08-27 13:35:46 +02:00
|
|
|
len = strlen(*names) + sizeof(EXEEXT) + 1;
|
2009-02-04 19:37:13 +01:00
|
|
|
file = xmalloc( maxlen + len );
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
strcpy( file, dirs[i] );
|
|
|
|
p = file + strlen(file);
|
|
|
|
if (p == file) *p++ = '.';
|
|
|
|
if (p[-1] != '/') *p++ = '/';
|
|
|
|
strcpy( p, *names );
|
2009-08-27 13:35:46 +02:00
|
|
|
strcat( p, EXEEXT );
|
2009-02-04 19:37:13 +01:00
|
|
|
|
|
|
|
if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111)) return file;
|
|
|
|
}
|
|
|
|
free( file );
|
|
|
|
names++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
const char *get_as_command(void)
|
|
|
|
{
|
|
|
|
if (!as_command)
|
|
|
|
{
|
|
|
|
if (target_alias)
|
|
|
|
{
|
|
|
|
as_command = xmalloc( strlen(target_alias) + sizeof("-as") );
|
|
|
|
strcpy( as_command, target_alias );
|
|
|
|
strcat( as_command, "-as" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 19:37:13 +01:00
|
|
|
static const char * const commands[] = { "gas", "as", NULL };
|
|
|
|
if (!(as_command = find_tool( commands ))) as_command = xstrdup("as");
|
2009-02-04 19:31:54 +01:00
|
|
|
}
|
2009-02-04 19:33:49 +01:00
|
|
|
|
|
|
|
if (force_pointer_size)
|
|
|
|
{
|
2009-05-02 05:59:36 +02:00
|
|
|
const char *args = (target_platform == PLATFORM_APPLE) ?
|
|
|
|
((force_pointer_size == 8) ? " -arch x86_64" : " -arch i386") :
|
|
|
|
((force_pointer_size == 8) ? " --64" : " --32");
|
2009-02-04 19:33:49 +01:00
|
|
|
as_command = xrealloc( as_command, strlen(as_command) + strlen(args) + 1 );
|
|
|
|
strcat( as_command, args );
|
|
|
|
}
|
2009-02-04 19:31:54 +01:00
|
|
|
}
|
|
|
|
return as_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get_ld_command(void)
|
|
|
|
{
|
|
|
|
if (!ld_command)
|
|
|
|
{
|
|
|
|
if (target_alias)
|
|
|
|
{
|
|
|
|
ld_command = xmalloc( strlen(target_alias) + sizeof("-ld") );
|
|
|
|
strcpy( ld_command, target_alias );
|
|
|
|
strcat( ld_command, "-ld" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 19:37:13 +01:00
|
|
|
static const char * const commands[] = { "ld", "gld", NULL };
|
|
|
|
if (!(ld_command = find_tool( commands ))) ld_command = xstrdup("ld");
|
2009-02-04 19:31:54 +01:00
|
|
|
}
|
2009-02-04 19:33:49 +01:00
|
|
|
|
|
|
|
if (force_pointer_size)
|
|
|
|
{
|
2009-10-15 00:20:39 +02:00
|
|
|
const char *args;
|
|
|
|
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
args = (force_pointer_size == 8) ? " -arch x86_64" : " -arch i386";
|
|
|
|
break;
|
|
|
|
case PLATFORM_FREEBSD:
|
|
|
|
args = (force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386_fbsd";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
args = (force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386";
|
|
|
|
break;
|
|
|
|
}
|
2009-02-04 19:33:49 +01:00
|
|
|
ld_command = xrealloc( ld_command, strlen(ld_command) + strlen(args) + 1 );
|
|
|
|
strcat( ld_command, args );
|
|
|
|
}
|
2009-02-04 19:31:54 +01:00
|
|
|
}
|
|
|
|
return ld_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get_nm_command(void)
|
|
|
|
{
|
|
|
|
if (!nm_command)
|
|
|
|
{
|
|
|
|
if (target_alias)
|
|
|
|
{
|
|
|
|
nm_command = xmalloc( strlen(target_alias) + sizeof("-nm") );
|
|
|
|
strcpy( nm_command, target_alias );
|
|
|
|
strcat( nm_command, "-nm" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 19:37:13 +01:00
|
|
|
static const char * const commands[] = { "nm", "gnm", NULL };
|
|
|
|
if (!(nm_command = find_tool( commands ))) nm_command = xstrdup("nm");
|
2009-02-04 19:31:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nm_command;
|
|
|
|
}
|
|
|
|
|
2009-05-30 21:39:50 +02:00
|
|
|
const char *get_windres_command(void)
|
|
|
|
{
|
|
|
|
static char *windres_command;
|
|
|
|
|
|
|
|
if (!windres_command)
|
|
|
|
{
|
|
|
|
if (target_alias)
|
|
|
|
{
|
|
|
|
windres_command = xmalloc( strlen(target_alias) + sizeof("-windres") );
|
|
|
|
strcpy( windres_command, target_alias );
|
|
|
|
strcat( windres_command, "-windres" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const char * const commands[] = { "windres", NULL };
|
|
|
|
if (!(windres_command = find_tool( commands ))) windres_command = xstrdup("windres");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return windres_command;
|
|
|
|
}
|
|
|
|
|
2005-09-19 17:24:13 +02:00
|
|
|
/* get a name for a temp file, automatically cleaned up on exit */
|
|
|
|
char *get_temp_file_name( const char *prefix, const char *suffix )
|
|
|
|
{
|
|
|
|
char *name;
|
2005-09-21 12:22:28 +02:00
|
|
|
const char *ext;
|
2005-09-19 17:24:13 +02:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
assert( nb_tmp_files < MAX_TMP_FILES );
|
2005-09-21 12:22:28 +02:00
|
|
|
if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
|
2005-09-19 17:24:13 +02:00
|
|
|
|
2005-09-21 12:22:28 +02:00
|
|
|
if (!prefix || !prefix[0]) prefix = "winebuild";
|
2005-09-19 17:24:13 +02:00
|
|
|
if (!suffix) suffix = "";
|
2005-09-21 12:22:28 +02:00
|
|
|
if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix);
|
|
|
|
name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
|
|
|
|
strcpy( name, "/tmp/" );
|
|
|
|
memcpy( name + 5, prefix, ext - prefix );
|
|
|
|
strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
|
|
|
|
strcat( name, suffix );
|
|
|
|
|
|
|
|
/* first try without the /tmp/ prefix */
|
|
|
|
if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1)
|
|
|
|
name += 5;
|
|
|
|
else if ((fd = mkstemps( name, strlen(suffix) )) == -1)
|
|
|
|
fatal_error( "could not generate a temp file\n" );
|
2005-09-19 17:24:13 +02:00
|
|
|
|
|
|
|
close( fd );
|
|
|
|
tmp_files[nb_tmp_files++] = name;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-08-14 13:22:26 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* buffer management
|
|
|
|
*
|
|
|
|
* Function for reading from/writing to a memory buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int byte_swapped = 0;
|
|
|
|
const char *input_buffer_filename;
|
|
|
|
const unsigned char *input_buffer;
|
|
|
|
size_t input_buffer_pos;
|
|
|
|
size_t input_buffer_size;
|
2009-08-14 13:26:09 +02:00
|
|
|
unsigned char *output_buffer;
|
|
|
|
size_t output_buffer_pos;
|
|
|
|
size_t output_buffer_size;
|
|
|
|
|
|
|
|
static void check_output_buffer_space( size_t size )
|
|
|
|
{
|
|
|
|
if (output_buffer_pos + size >= output_buffer_size)
|
|
|
|
{
|
|
|
|
output_buffer_size = max( output_buffer_size * 2, output_buffer_pos + size );
|
|
|
|
output_buffer = xrealloc( output_buffer, output_buffer_size );
|
|
|
|
}
|
|
|
|
}
|
2009-08-14 13:22:26 +02:00
|
|
|
|
|
|
|
void init_input_buffer( const char *file )
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if ((fd = open( file, O_RDONLY | O_BINARY )) == -1) fatal_perror( "Cannot open %s", file );
|
|
|
|
if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", file );
|
|
|
|
if (!st.st_size) fatal_error( "%s is an empty file\n", file );
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
if ((input_buffer = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
unsigned char *buffer = xmalloc( st.st_size );
|
|
|
|
if (read( fd, buffer, st.st_size ) != st.st_size) fatal_error( "Cannot read %s\n", file );
|
|
|
|
input_buffer = buffer;
|
|
|
|
}
|
|
|
|
close( fd );
|
|
|
|
input_buffer_filename = xstrdup( file );
|
|
|
|
input_buffer_size = st.st_size;
|
|
|
|
input_buffer_pos = 0;
|
|
|
|
byte_swapped = 0;
|
|
|
|
}
|
|
|
|
|
2009-08-14 13:26:09 +02:00
|
|
|
void init_output_buffer(void)
|
|
|
|
{
|
|
|
|
output_buffer_size = 1024;
|
|
|
|
output_buffer_pos = 0;
|
|
|
|
output_buffer = xmalloc( output_buffer_size );
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush_output_buffer(void)
|
|
|
|
{
|
|
|
|
if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
|
|
|
|
fatal_error( "Error writing to %s\n", output_file_name );
|
|
|
|
free( output_buffer );
|
|
|
|
}
|
|
|
|
|
2009-08-14 13:22:26 +02:00
|
|
|
unsigned char get_byte(void)
|
|
|
|
{
|
|
|
|
if (input_buffer_pos >= input_buffer_size)
|
|
|
|
fatal_error( "%s is a truncated file\n", input_buffer_filename );
|
|
|
|
return input_buffer[input_buffer_pos++];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short get_word(void)
|
|
|
|
{
|
|
|
|
unsigned short ret;
|
|
|
|
|
|
|
|
if (input_buffer_pos + sizeof(ret) > input_buffer_size)
|
|
|
|
fatal_error( "%s is a truncated file\n", input_buffer_filename );
|
|
|
|
memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
|
|
|
|
if (byte_swapped) ret = (ret << 8) | (ret >> 8);
|
|
|
|
input_buffer_pos += sizeof(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int get_dword(void)
|
|
|
|
{
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
if (input_buffer_pos + sizeof(ret) > input_buffer_size)
|
|
|
|
fatal_error( "%s is a truncated file\n", input_buffer_filename );
|
|
|
|
memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
|
|
|
|
if (byte_swapped)
|
|
|
|
ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
|
|
|
|
input_buffer_pos += sizeof(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-14 13:26:09 +02:00
|
|
|
void put_data( const void *data, size_t size )
|
|
|
|
{
|
|
|
|
check_output_buffer_space( size );
|
|
|
|
memcpy( output_buffer + output_buffer_pos, data, size );
|
|
|
|
output_buffer_pos += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void put_byte( unsigned char val )
|
|
|
|
{
|
|
|
|
check_output_buffer_space( 1 );
|
|
|
|
output_buffer[output_buffer_pos++] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void put_word( unsigned short val )
|
|
|
|
{
|
|
|
|
if (byte_swapped) val = (val << 8) | (val >> 8);
|
|
|
|
put_data( &val, sizeof(val) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void put_dword( unsigned int val )
|
|
|
|
{
|
|
|
|
if (byte_swapped)
|
|
|
|
val = ((val << 24) | ((val << 8) & 0x00ff0000) | ((val >> 8) & 0x0000ff00) | (val >> 24));
|
|
|
|
put_data( &val, sizeof(val) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void put_qword( unsigned int val )
|
|
|
|
{
|
|
|
|
if (byte_swapped)
|
|
|
|
{
|
|
|
|
put_dword( 0 );
|
|
|
|
put_dword( val );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
put_dword( val );
|
|
|
|
put_dword( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pointer-sized word */
|
|
|
|
void put_pword( unsigned int val )
|
|
|
|
{
|
|
|
|
if (get_ptr_size() == 8) put_qword( val );
|
|
|
|
else put_dword( val );
|
|
|
|
}
|
|
|
|
|
|
|
|
void align_output( unsigned int align )
|
|
|
|
{
|
|
|
|
size_t size = align - (output_buffer_pos % align);
|
|
|
|
|
|
|
|
if (size == align) return;
|
|
|
|
check_output_buffer_space( size );
|
|
|
|
memset( output_buffer + output_buffer_pos, 0, size );
|
|
|
|
output_buffer_pos += size;
|
|
|
|
}
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
/* output a standard header for generated files */
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_standard_file_header(void)
|
2002-03-10 00:29:33 +01:00
|
|
|
{
|
2005-03-15 16:42:32 +01:00
|
|
|
if (spec_file_name)
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name );
|
2002-05-12 01:06:32 +02:00
|
|
|
else
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "/* File generated automatically; do not edit! */\n" );
|
|
|
|
output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
|
2002-03-10 00:29:33 +01:00
|
|
|
}
|
|
|
|
|
2000-06-23 22:15:35 +02:00
|
|
|
/* dump a byte stream into the assembly code */
|
2006-08-11 20:41:29 +02:00
|
|
|
void dump_bytes( const void *buffer, unsigned int size )
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2005-09-21 13:50:04 +02:00
|
|
|
unsigned int i;
|
|
|
|
const unsigned char *ptr = buffer;
|
2000-06-23 22:15:35 +02:00
|
|
|
|
2005-09-21 13:50:04 +02:00
|
|
|
if (!size) return;
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.byte " );
|
2005-09-21 13:50:04 +02:00
|
|
|
for (i = 0; i < size - 1; i++, ptr++)
|
2000-06-23 22:15:35 +02:00
|
|
|
{
|
2006-08-11 20:41:29 +02:00
|
|
|
if ((i % 16) == 15) output( "0x%02x\n\t.byte ", *ptr );
|
|
|
|
else output( "0x%02x,", *ptr );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "0x%02x\n", *ptr );
|
2000-06-23 22:15:35 +02:00
|
|
|
}
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2002-05-14 22:54:58 +02:00
|
|
|
|
2002-08-01 20:34:12 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* open_input_file
|
|
|
|
*
|
|
|
|
* Open a file in the given srcdir and set the input_file_name global variable.
|
|
|
|
*/
|
|
|
|
FILE *open_input_file( const char *srcdir, const char *name )
|
|
|
|
{
|
|
|
|
char *fullname;
|
2003-11-20 05:21:56 +01:00
|
|
|
FILE *file = fopen( name, "r" );
|
2002-08-01 20:34:12 +02:00
|
|
|
|
2003-11-20 05:21:56 +01:00
|
|
|
if (!file && srcdir)
|
2002-08-01 20:34:12 +02:00
|
|
|
{
|
|
|
|
fullname = xmalloc( strlen(srcdir) + strlen(name) + 2 );
|
|
|
|
strcpy( fullname, srcdir );
|
|
|
|
strcat( fullname, "/" );
|
|
|
|
strcat( fullname, name );
|
2003-11-20 05:21:56 +01:00
|
|
|
file = fopen( fullname, "r" );
|
2002-08-01 20:34:12 +02:00
|
|
|
}
|
|
|
|
else fullname = xstrdup( name );
|
|
|
|
|
2003-11-20 05:21:56 +01:00
|
|
|
if (!file) fatal_error( "Cannot open file '%s'\n", fullname );
|
2002-08-01 20:34:12 +02:00
|
|
|
input_file_name = fullname;
|
|
|
|
current_line = 1;
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* close_input_file
|
|
|
|
*
|
|
|
|
* Close the current input file (must have been opened with open_input_file).
|
|
|
|
*/
|
|
|
|
void close_input_file( FILE *file )
|
|
|
|
{
|
|
|
|
fclose( file );
|
|
|
|
free( input_file_name );
|
|
|
|
input_file_name = NULL;
|
|
|
|
current_line = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* remove_stdcall_decoration
|
|
|
|
*
|
|
|
|
* Remove a possible @xx suffix from a function name.
|
|
|
|
* Return the numerical value of the suffix, or -1 if none.
|
|
|
|
*/
|
|
|
|
int remove_stdcall_decoration( char *name )
|
|
|
|
{
|
|
|
|
char *p, *end = strrchr( name, '@' );
|
|
|
|
if (!end || !end[1] || end == name) return -1;
|
|
|
|
/* make sure all the rest is digits */
|
|
|
|
for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
|
|
|
|
*end = 0;
|
|
|
|
return atoi( end + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-21 12:22:28 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* assemble_file
|
|
|
|
*
|
|
|
|
* Run a file through the assembler.
|
|
|
|
*/
|
|
|
|
void assemble_file( const char *src_file, const char *obj_file )
|
|
|
|
{
|
2009-02-04 19:31:54 +01:00
|
|
|
const char *prog = get_as_command();
|
2005-09-21 12:22:28 +02:00
|
|
|
char *cmd;
|
|
|
|
int err;
|
|
|
|
|
2009-02-04 19:31:54 +01:00
|
|
|
cmd = xmalloc( strlen(prog) + strlen(obj_file) + strlen(src_file) + 6 );
|
|
|
|
sprintf( cmd, "%s -o %s %s", prog, obj_file, src_file );
|
2005-09-21 12:22:28 +02:00
|
|
|
if (verbose) fprintf( stderr, "%s\n", cmd );
|
|
|
|
err = system( cmd );
|
2009-02-04 19:31:54 +01:00
|
|
|
if (err) fatal_error( "%s failed with status %d\n", prog, err );
|
2005-09-21 12:22:28 +02:00
|
|
|
free( cmd );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-17 21:36:16 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* alloc_dll_spec
|
|
|
|
*
|
|
|
|
* Create a new dll spec file descriptor
|
|
|
|
*/
|
|
|
|
DLLSPEC *alloc_dll_spec(void)
|
|
|
|
{
|
|
|
|
DLLSPEC *spec;
|
|
|
|
|
|
|
|
spec = xmalloc( sizeof(*spec) );
|
|
|
|
spec->file_name = NULL;
|
|
|
|
spec->dll_name = NULL;
|
|
|
|
spec->init_func = NULL;
|
2009-03-24 11:50:13 +01:00
|
|
|
spec->main_module = NULL;
|
2004-02-17 21:36:16 +01:00
|
|
|
spec->type = SPEC_WIN32;
|
|
|
|
spec->base = MAX_ORDINALS;
|
|
|
|
spec->limit = 0;
|
|
|
|
spec->stack_size = 0;
|
|
|
|
spec->heap_size = 0;
|
|
|
|
spec->nb_entry_points = 0;
|
|
|
|
spec->alloc_entry_points = 0;
|
|
|
|
spec->nb_names = 0;
|
|
|
|
spec->nb_resources = 0;
|
2007-05-24 12:54:27 +02:00
|
|
|
spec->characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
|
2007-05-28 06:44:46 +02:00
|
|
|
if (get_ptr_size() > 4)
|
|
|
|
spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
|
2007-09-04 09:52:16 +02:00
|
|
|
else
|
|
|
|
spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
|
2006-12-07 20:51:49 +01:00
|
|
|
spec->dll_characteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
2004-03-25 01:40:52 +01:00
|
|
|
spec->subsystem = 0;
|
|
|
|
spec->subsystem_major = 4;
|
|
|
|
spec->subsystem_minor = 0;
|
2004-02-17 21:36:16 +01:00
|
|
|
spec->entry_points = NULL;
|
|
|
|
spec->names = NULL;
|
|
|
|
spec->ordinals = NULL;
|
|
|
|
spec->resources = NULL;
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* free_dll_spec
|
|
|
|
*
|
|
|
|
* Free dll spec file descriptor
|
|
|
|
*/
|
|
|
|
void free_dll_spec( DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < spec->nb_entry_points; i++)
|
|
|
|
{
|
|
|
|
ORDDEF *odp = &spec->entry_points[i];
|
|
|
|
free( odp->name );
|
|
|
|
free( odp->export_name );
|
|
|
|
free( odp->link_name );
|
|
|
|
}
|
|
|
|
free( spec->file_name );
|
|
|
|
free( spec->dll_name );
|
|
|
|
free( spec->init_func );
|
|
|
|
free( spec->entry_points );
|
|
|
|
free( spec->names );
|
|
|
|
free( spec->ordinals );
|
|
|
|
free( spec->resources );
|
|
|
|
free( spec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-14 22:54:58 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* make_c_identifier
|
|
|
|
*
|
|
|
|
* Map a string to a valid C identifier.
|
|
|
|
*/
|
|
|
|
const char *make_c_identifier( const char *str )
|
|
|
|
{
|
|
|
|
static char buffer[256];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
for (p = buffer; *str && p < buffer+sizeof(buffer)-1; p++, str++)
|
|
|
|
{
|
|
|
|
if (isalnum(*str)) *p = *str;
|
|
|
|
else *p = '_';
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-21 12:57:04 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* get_stub_name
|
|
|
|
*
|
|
|
|
* Generate an internal name for a stub entry point.
|
|
|
|
*/
|
|
|
|
const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
|
|
|
|
{
|
|
|
|
static char buffer[256];
|
|
|
|
if (odp->name || odp->export_name)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
sprintf( buffer, "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
|
|
|
|
/* make sure name is a legal C identifier */
|
|
|
|
for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
|
|
|
|
if (!*p) return buffer;
|
|
|
|
}
|
|
|
|
sprintf( buffer, "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2008-12-08 17:07:50 +01:00
|
|
|
/* parse a cpu name and return the corresponding value */
|
|
|
|
enum target_cpu get_cpu_from_name( const char *name )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
|
|
|
|
if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-09-21 12:57:04 +02:00
|
|
|
|
2001-02-13 03:06:38 +01:00
|
|
|
/*****************************************************************
|
|
|
|
* Function: get_alignment
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* According to the info page for gas, the .align directive behaves
|
|
|
|
* differently on different systems. On some architectures, the
|
|
|
|
* argument of a .align directive is the number of bytes to pad to, so
|
|
|
|
* to align on an 8-byte boundary you'd say
|
|
|
|
* .align 8
|
|
|
|
* On other systems, the argument is "the number of low-order zero bits
|
|
|
|
* that the location counter must have after advancement." So to
|
|
|
|
* align on an 8-byte boundary you'd say
|
|
|
|
* .align 3
|
|
|
|
*
|
|
|
|
* The reason gas is written this way is that it's trying to mimick
|
|
|
|
* native assemblers for the various architectures it runs on. gas
|
2005-12-02 16:15:09 +01:00
|
|
|
* provides other directives that work consistently across
|
2001-02-13 03:06:38 +01:00
|
|
|
* architectures, but of course we want to work on all arches with or
|
|
|
|
* without gas. Hence this function.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2001-02-13 03:06:38 +01:00
|
|
|
*
|
|
|
|
* Parameters:
|
2005-06-27 13:23:24 +02:00
|
|
|
* align -- the number of bytes to align to. Must be a power of 2.
|
2001-02-13 03:06:38 +01:00
|
|
|
*/
|
2005-06-27 13:23:24 +02:00
|
|
|
unsigned int get_alignment(unsigned int align)
|
2001-02-13 03:06:38 +01:00
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
unsigned int n;
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
assert( !(align & (align - 1)) );
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
switch(target_cpu)
|
2001-02-13 03:06:38 +01:00
|
|
|
{
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_x86:
|
2005-09-07 15:31:37 +02:00
|
|
|
case CPU_x86_64:
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_SPARC:
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
2005-06-27 13:23:24 +02:00
|
|
|
if (target_platform != PLATFORM_APPLE) return align;
|
|
|
|
/* fall through */
|
|
|
|
case CPU_POWERPC:
|
|
|
|
case CPU_ALPHA:
|
|
|
|
n = 0;
|
2007-03-03 14:30:03 +01:00
|
|
|
while ((1u << n) != align) n++;
|
2005-06-27 13:23:24 +02:00
|
|
|
return n;
|
2001-02-13 03:06:38 +01:00
|
|
|
}
|
2005-06-27 13:23:24 +02:00
|
|
|
/* unreached */
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
/* return the page size for the target CPU */
|
|
|
|
unsigned int get_page_size(void)
|
|
|
|
{
|
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86: return 4096;
|
2005-09-07 15:31:37 +02:00
|
|
|
case CPU_x86_64: return 4096;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_POWERPC: return 4096;
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM: return 4096;
|
2005-06-27 13:23:24 +02:00
|
|
|
case CPU_SPARC: return 8192;
|
|
|
|
case CPU_ALPHA: return 8192;
|
|
|
|
}
|
|
|
|
/* unreached */
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-07 15:31:37 +02:00
|
|
|
/* return the size of a pointer on the target CPU */
|
|
|
|
unsigned int get_ptr_size(void)
|
|
|
|
{
|
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_x86:
|
|
|
|
case CPU_POWERPC:
|
|
|
|
case CPU_SPARC:
|
|
|
|
case CPU_ALPHA:
|
2009-11-17 20:20:48 +01:00
|
|
|
case CPU_ARM:
|
2005-09-07 15:31:37 +02:00
|
|
|
return 4;
|
|
|
|
case CPU_x86_64:
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
/* unreached */
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-27 20:59:54 +02:00
|
|
|
/* return the assembly name for a C symbol */
|
|
|
|
const char *asm_name( const char *sym )
|
2005-06-27 13:23:24 +02:00
|
|
|
{
|
|
|
|
static char buffer[256];
|
2005-06-29 22:18:58 +02:00
|
|
|
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
case PLATFORM_WINDOWS:
|
2009-02-27 17:39:54 +01:00
|
|
|
if (sym[0] == '.' && sym[1] == 'L') return sym;
|
2005-06-29 22:18:58 +02:00
|
|
|
buffer[0] = '_';
|
|
|
|
strcpy( buffer + 1, sym );
|
|
|
|
return buffer;
|
|
|
|
default:
|
|
|
|
return sym;
|
|
|
|
}
|
2005-06-27 13:23:24 +02:00
|
|
|
}
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2005-06-27 13:23:24 +02:00
|
|
|
/* return an assembly function declaration for a C function name */
|
|
|
|
const char *func_declaration( const char *func )
|
|
|
|
{
|
|
|
|
static char buffer[256];
|
2005-06-29 22:18:58 +02:00
|
|
|
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
2005-06-30 13:00:28 +02:00
|
|
|
case PLATFORM_APPLE:
|
|
|
|
return "";
|
2005-06-29 22:18:58 +02:00
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
sprintf( buffer, ".def _%s; .scl 2; .type 32; .endef", func );
|
|
|
|
break;
|
|
|
|
default:
|
2009-11-17 20:20:48 +01:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_ARM:
|
|
|
|
sprintf( buffer, ".type %s,%%function", func );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf( buffer, ".type %s,@function", func );
|
|
|
|
break;
|
|
|
|
}
|
2005-06-29 22:18:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-06-27 13:23:24 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
2001-02-13 03:06:38 +01:00
|
|
|
|
2005-09-21 13:50:04 +02:00
|
|
|
/* output a size declaration for an assembly function */
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_function_size( const char *name )
|
2005-06-27 13:23:24 +02:00
|
|
|
{
|
2005-06-29 22:18:58 +02:00
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
case PLATFORM_WINDOWS:
|
2005-09-21 13:50:04 +02:00
|
|
|
break;
|
2005-06-29 22:18:58 +02:00
|
|
|
default:
|
2006-08-11 20:41:29 +02:00
|
|
|
output( "\t.size %s, .-%s\n", name, name );
|
2005-09-21 13:50:04 +02:00
|
|
|
break;
|
2005-06-29 22:18:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-21 19:23:36 +01:00
|
|
|
/* output the GNU note for non-exec stack */
|
2006-08-11 20:41:29 +02:00
|
|
|
void output_gnu_stack_note(void)
|
2006-01-21 19:23:36 +01:00
|
|
|
{
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
break;
|
|
|
|
default:
|
2009-11-17 20:20:48 +01:00
|
|
|
switch(target_cpu)
|
|
|
|
{
|
|
|
|
case CPU_ARM:
|
|
|
|
output( "\t.section .note.GNU-stack,\"\",%%progbits\n" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
|
|
|
|
break;
|
|
|
|
}
|
2006-01-21 19:23:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-15 20:48:39 +02:00
|
|
|
/* return a global symbol declaration for an assembly symbol */
|
|
|
|
const char *asm_globl( const char *func )
|
|
|
|
{
|
|
|
|
static char buffer[256];
|
|
|
|
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE:
|
|
|
|
sprintf( buffer, "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
|
|
|
|
return buffer;
|
|
|
|
case PLATFORM_WINDOWS:
|
|
|
|
sprintf( buffer, "\t.globl _%s\n_%s:", func, func );
|
|
|
|
return buffer;
|
|
|
|
default:
|
|
|
|
sprintf( buffer, "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-07 15:31:37 +02:00
|
|
|
const char *get_asm_ptr_keyword(void)
|
|
|
|
{
|
|
|
|
switch(get_ptr_size())
|
|
|
|
{
|
|
|
|
case 4: return ".long";
|
|
|
|
case 8: return ".quad";
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-29 22:18:58 +02:00
|
|
|
const char *get_asm_string_keyword(void)
|
|
|
|
{
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
2005-06-30 13:00:28 +02:00
|
|
|
case PLATFORM_APPLE:
|
|
|
|
return ".asciz";
|
|
|
|
default:
|
|
|
|
return ".string";
|
2005-06-29 22:18:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get_asm_short_keyword(void)
|
|
|
|
{
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
default: return ".short";
|
|
|
|
}
|
2001-02-13 03:06:38 +01:00
|
|
|
}
|
2005-09-14 21:18:05 +02:00
|
|
|
|
2005-12-18 10:45:01 +01:00
|
|
|
const char *get_asm_rodata_section(void)
|
|
|
|
{
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE: return ".const";
|
|
|
|
default: return ".section .rodata";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-14 21:18:05 +02:00
|
|
|
const char *get_asm_string_section(void)
|
|
|
|
{
|
|
|
|
switch (target_platform)
|
|
|
|
{
|
|
|
|
case PLATFORM_APPLE: return ".cstring";
|
|
|
|
default: return ".section .rodata";
|
|
|
|
}
|
|
|
|
}
|