wpp: Build with -fPIC to allow libwpp to be used from dlls.
[wine/multimedia.git] / tools / winebuild / utils.c
blob31bf691967efae7f9862eea2cf4345b1123537b5
1 /*
2 * Small utility functions for winebuild
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <ctype.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #ifdef HAVE_SYS_STAT_H
34 # include <sys/stat.h>
35 #endif
36 #ifdef HAVE_SYS_MMAN_H
37 #include <sys/mman.h>
38 #endif
40 #include "build.h"
42 #define MAX_TMP_FILES 8
43 static const char *tmp_files[MAX_TMP_FILES];
44 static unsigned int nb_tmp_files;
46 static const struct
48 const char *name;
49 enum target_cpu cpu;
50 } cpu_names[] =
52 { "i386", CPU_x86 },
53 { "i486", CPU_x86 },
54 { "i586", CPU_x86 },
55 { "i686", CPU_x86 },
56 { "i786", CPU_x86 },
57 { "x86_64", CPU_x86_64 },
58 { "sparc", CPU_SPARC },
59 { "alpha", CPU_ALPHA },
60 { "powerpc", CPU_POWERPC },
61 { "arm", CPU_ARM }
64 /* atexit handler to clean tmp files */
65 static void cleanup_tmp_files(void)
67 unsigned int i;
68 for (i = 0; i < MAX_TMP_FILES; i++) if (tmp_files[i]) unlink( tmp_files[i] );
72 void *xmalloc (size_t size)
74 void *res;
76 res = malloc (size ? size : 1);
77 if (res == NULL)
79 fprintf (stderr, "Virtual memory exhausted.\n");
80 exit (1);
82 return res;
85 void *xrealloc (void *ptr, size_t size)
87 void *res = realloc (ptr, size);
88 if (size && res == NULL)
90 fprintf (stderr, "Virtual memory exhausted.\n");
91 exit (1);
93 return res;
96 char *xstrdup( const char *str )
98 char *res = strdup( str );
99 if (!res)
101 fprintf (stderr, "Virtual memory exhausted.\n");
102 exit (1);
104 return res;
107 char *strupper(char *s)
109 char *p;
110 for (p = s; *p; p++) *p = toupper(*p);
111 return s;
114 int strendswith(const char* str, const char* end)
116 int l = strlen(str);
117 int m = strlen(end);
118 return l >= m && strcmp(str + l - m, end) == 0;
121 void fatal_error( const char *msg, ... )
123 va_list valist;
124 va_start( valist, msg );
125 if (input_file_name)
127 fprintf( stderr, "%s:", input_file_name );
128 if (current_line)
129 fprintf( stderr, "%d:", current_line );
130 fputc( ' ', stderr );
132 else fprintf( stderr, "winebuild: " );
133 vfprintf( stderr, msg, valist );
134 va_end( valist );
135 exit(1);
138 void fatal_perror( const char *msg, ... )
140 va_list valist;
141 va_start( valist, msg );
142 if (input_file_name)
144 fprintf( stderr, "%s:", input_file_name );
145 if (current_line)
146 fprintf( stderr, "%d:", current_line );
147 fputc( ' ', stderr );
149 vfprintf( stderr, msg, valist );
150 perror( " " );
151 va_end( valist );
152 exit(1);
155 void error( const char *msg, ... )
157 va_list valist;
158 va_start( valist, msg );
159 if (input_file_name)
161 fprintf( stderr, "%s:", input_file_name );
162 if (current_line)
163 fprintf( stderr, "%d:", current_line );
164 fputc( ' ', stderr );
166 vfprintf( stderr, msg, valist );
167 va_end( valist );
168 nb_errors++;
171 void warning( const char *msg, ... )
173 va_list valist;
175 if (!display_warnings) return;
176 va_start( valist, msg );
177 if (input_file_name)
179 fprintf( stderr, "%s:", input_file_name );
180 if (current_line)
181 fprintf( stderr, "%d:", current_line );
182 fputc( ' ', stderr );
184 fprintf( stderr, "warning: " );
185 vfprintf( stderr, msg, valist );
186 va_end( valist );
189 int output( const char *format, ... )
191 int ret;
192 va_list valist;
194 va_start( valist, format );
195 ret = vfprintf( output_file, format, valist );
196 va_end( valist );
197 if (ret < 0) fatal_perror( "Output error" );
198 return ret;
201 /* find a build tool in the path, trying the various names */
202 char *find_tool( const char *name, const char * const *names )
204 static char **dirs;
205 static unsigned int count, maxlen;
207 char *p, *file;
208 const char *alt_names[2];
209 unsigned int i, len;
210 struct stat st;
212 if (target_alias)
214 file = xmalloc( strlen(target_alias) + strlen(name) + 2 );
215 strcpy( file, target_alias );
216 strcat( file, "-" );
217 strcat( file, name );
218 return file;
221 if (!dirs)
223 char *path;
225 /* split the path in directories */
227 if (!getenv( "PATH" )) return NULL;
228 path = xstrdup( getenv( "PATH" ));
229 for (p = path, count = 2; *p; p++) if (*p == ':') count++;
230 dirs = xmalloc( count * sizeof(*dirs) );
231 count = 0;
232 dirs[count++] = p = path;
233 while (*p)
235 while (*p && *p != ':') p++;
236 if (!*p) break;
237 *p++ = 0;
238 dirs[count++] = p;
240 for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 );
243 if (!names)
245 alt_names[0] = name;
246 alt_names[1] = NULL;
247 names = alt_names;
250 while (*names)
252 len = strlen(*names) + sizeof(EXEEXT) + 1;
253 file = xmalloc( maxlen + len );
255 for (i = 0; i < count; i++)
257 strcpy( file, dirs[i] );
258 p = file + strlen(file);
259 if (p == file) *p++ = '.';
260 if (p[-1] != '/') *p++ = '/';
261 strcpy( p, *names );
262 strcat( p, EXEEXT );
264 if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111)) return file;
266 free( file );
267 names++;
269 return xstrdup( name );
272 const char *get_as_command(void)
274 if (!as_command)
276 static const char * const commands[] = { "gas", "as", NULL };
277 as_command = find_tool( "as", commands );
279 if (force_pointer_size)
281 const char *args = (target_platform == PLATFORM_APPLE) ?
282 ((force_pointer_size == 8) ? " -arch x86_64" : " -arch i386") :
283 ((force_pointer_size == 8) ? " --64" : " --32");
284 as_command = xrealloc( as_command, strlen(as_command) + strlen(args) + 1 );
285 strcat( as_command, args );
288 return as_command;
291 const char *get_ld_command(void)
293 if (!ld_command)
295 static const char * const commands[] = { "ld", "gld", NULL };
296 ld_command = find_tool( "ld", commands );
298 if (force_pointer_size)
300 const char *args;
302 switch (target_platform)
304 case PLATFORM_APPLE:
305 args = (force_pointer_size == 8) ? " -arch x86_64" : " -arch i386";
306 break;
307 case PLATFORM_FREEBSD:
308 args = (force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386_fbsd";
309 break;
310 default:
311 args = (force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386";
312 break;
314 ld_command = xrealloc( ld_command, strlen(ld_command) + strlen(args) + 1 );
315 strcat( ld_command, args );
318 return ld_command;
321 const char *get_nm_command(void)
323 if (!nm_command)
325 static const char * const commands[] = { "nm", "gnm", NULL };
326 nm_command = find_tool( "nm", commands );
328 return nm_command;
331 /* get a name for a temp file, automatically cleaned up on exit */
332 char *get_temp_file_name( const char *prefix, const char *suffix )
334 char *name;
335 const char *ext;
336 int fd;
338 assert( nb_tmp_files < MAX_TMP_FILES );
339 if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
341 if (!prefix || !prefix[0]) prefix = "winebuild";
342 if (!suffix) suffix = "";
343 if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix);
344 name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
345 strcpy( name, "/tmp/" );
346 memcpy( name + 5, prefix, ext - prefix );
347 strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
348 strcat( name, suffix );
350 /* first try without the /tmp/ prefix */
351 if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1)
352 name += 5;
353 else if ((fd = mkstemps( name, strlen(suffix) )) == -1)
354 fatal_error( "could not generate a temp file\n" );
356 close( fd );
357 tmp_files[nb_tmp_files++] = name;
358 return name;
361 /*******************************************************************
362 * buffer management
364 * Function for reading from/writing to a memory buffer.
367 int byte_swapped = 0;
368 const char *input_buffer_filename;
369 const unsigned char *input_buffer;
370 size_t input_buffer_pos;
371 size_t input_buffer_size;
372 unsigned char *output_buffer;
373 size_t output_buffer_pos;
374 size_t output_buffer_size;
376 static void check_output_buffer_space( size_t size )
378 if (output_buffer_pos + size >= output_buffer_size)
380 output_buffer_size = max( output_buffer_size * 2, output_buffer_pos + size );
381 output_buffer = xrealloc( output_buffer, output_buffer_size );
385 void init_input_buffer( const char *file )
387 int fd;
388 struct stat st;
390 if ((fd = open( file, O_RDONLY | O_BINARY )) == -1) fatal_perror( "Cannot open %s", file );
391 if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", file );
392 if (!st.st_size) fatal_error( "%s is an empty file\n", file );
393 #ifdef HAVE_MMAP
394 if ((input_buffer = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
395 #endif
397 unsigned char *buffer = xmalloc( st.st_size );
398 if (read( fd, buffer, st.st_size ) != st.st_size) fatal_error( "Cannot read %s\n", file );
399 input_buffer = buffer;
401 close( fd );
402 input_buffer_filename = xstrdup( file );
403 input_buffer_size = st.st_size;
404 input_buffer_pos = 0;
405 byte_swapped = 0;
408 void init_output_buffer(void)
410 output_buffer_size = 1024;
411 output_buffer_pos = 0;
412 output_buffer = xmalloc( output_buffer_size );
415 void flush_output_buffer(void)
417 if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
418 fatal_error( "Error writing to %s\n", output_file_name );
419 free( output_buffer );
422 unsigned char get_byte(void)
424 if (input_buffer_pos >= input_buffer_size)
425 fatal_error( "%s is a truncated file\n", input_buffer_filename );
426 return input_buffer[input_buffer_pos++];
429 unsigned short get_word(void)
431 unsigned short ret;
433 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
434 fatal_error( "%s is a truncated file\n", input_buffer_filename );
435 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
436 if (byte_swapped) ret = (ret << 8) | (ret >> 8);
437 input_buffer_pos += sizeof(ret);
438 return ret;
441 unsigned int get_dword(void)
443 unsigned int ret;
445 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
446 fatal_error( "%s is a truncated file\n", input_buffer_filename );
447 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
448 if (byte_swapped)
449 ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
450 input_buffer_pos += sizeof(ret);
451 return ret;
454 void put_data( const void *data, size_t size )
456 check_output_buffer_space( size );
457 memcpy( output_buffer + output_buffer_pos, data, size );
458 output_buffer_pos += size;
461 void put_byte( unsigned char val )
463 check_output_buffer_space( 1 );
464 output_buffer[output_buffer_pos++] = val;
467 void put_word( unsigned short val )
469 if (byte_swapped) val = (val << 8) | (val >> 8);
470 put_data( &val, sizeof(val) );
473 void put_dword( unsigned int val )
475 if (byte_swapped)
476 val = ((val << 24) | ((val << 8) & 0x00ff0000) | ((val >> 8) & 0x0000ff00) | (val >> 24));
477 put_data( &val, sizeof(val) );
480 void put_qword( unsigned int val )
482 if (byte_swapped)
484 put_dword( 0 );
485 put_dword( val );
487 else
489 put_dword( val );
490 put_dword( 0 );
494 /* pointer-sized word */
495 void put_pword( unsigned int val )
497 if (get_ptr_size() == 8) put_qword( val );
498 else put_dword( val );
501 void align_output( unsigned int align )
503 size_t size = align - (output_buffer_pos % align);
505 if (size == align) return;
506 check_output_buffer_space( size );
507 memset( output_buffer + output_buffer_pos, 0, size );
508 output_buffer_pos += size;
511 /* output a standard header for generated files */
512 void output_standard_file_header(void)
514 if (spec_file_name)
515 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name );
516 else
517 output( "/* File generated automatically; do not edit! */\n" );
518 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
521 /* dump a byte stream into the assembly code */
522 void dump_bytes( const void *buffer, unsigned int size )
524 unsigned int i;
525 const unsigned char *ptr = buffer;
527 if (!size) return;
528 output( "\t.byte " );
529 for (i = 0; i < size - 1; i++, ptr++)
531 if ((i % 16) == 15) output( "0x%02x\n\t.byte ", *ptr );
532 else output( "0x%02x,", *ptr );
534 output( "0x%02x\n", *ptr );
538 /*******************************************************************
539 * open_input_file
541 * Open a file in the given srcdir and set the input_file_name global variable.
543 FILE *open_input_file( const char *srcdir, const char *name )
545 char *fullname;
546 FILE *file = fopen( name, "r" );
548 if (!file && srcdir)
550 fullname = xmalloc( strlen(srcdir) + strlen(name) + 2 );
551 strcpy( fullname, srcdir );
552 strcat( fullname, "/" );
553 strcat( fullname, name );
554 file = fopen( fullname, "r" );
556 else fullname = xstrdup( name );
558 if (!file) fatal_error( "Cannot open file '%s'\n", fullname );
559 input_file_name = fullname;
560 current_line = 1;
561 return file;
565 /*******************************************************************
566 * close_input_file
568 * Close the current input file (must have been opened with open_input_file).
570 void close_input_file( FILE *file )
572 fclose( file );
573 free( input_file_name );
574 input_file_name = NULL;
575 current_line = 0;
579 /*******************************************************************
580 * remove_stdcall_decoration
582 * Remove a possible @xx suffix from a function name.
583 * Return the numerical value of the suffix, or -1 if none.
585 int remove_stdcall_decoration( char *name )
587 char *p, *end = strrchr( name, '@' );
588 if (!end || !end[1] || end == name) return -1;
589 /* make sure all the rest is digits */
590 for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
591 *end = 0;
592 return atoi( end + 1 );
596 /*******************************************************************
597 * assemble_file
599 * Run a file through the assembler.
601 void assemble_file( const char *src_file, const char *obj_file )
603 const char *prog = get_as_command();
604 char *cmd;
605 int err;
607 cmd = xmalloc( strlen(prog) + strlen(obj_file) + strlen(src_file) + 6 );
608 sprintf( cmd, "%s -o %s %s", prog, obj_file, src_file );
609 if (verbose) fprintf( stderr, "%s\n", cmd );
610 err = system( cmd );
611 if (err) fatal_error( "%s failed with status %d\n", prog, err );
612 free( cmd );
616 /*******************************************************************
617 * alloc_dll_spec
619 * Create a new dll spec file descriptor
621 DLLSPEC *alloc_dll_spec(void)
623 DLLSPEC *spec;
625 spec = xmalloc( sizeof(*spec) );
626 spec->file_name = NULL;
627 spec->dll_name = NULL;
628 spec->init_func = NULL;
629 spec->main_module = NULL;
630 spec->type = SPEC_WIN32;
631 spec->base = MAX_ORDINALS;
632 spec->limit = 0;
633 spec->stack_size = 0;
634 spec->heap_size = 0;
635 spec->nb_entry_points = 0;
636 spec->alloc_entry_points = 0;
637 spec->nb_names = 0;
638 spec->nb_resources = 0;
639 spec->characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
640 if (get_ptr_size() > 4)
641 spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
642 else
643 spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
644 spec->dll_characteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
645 spec->subsystem = 0;
646 spec->subsystem_major = 4;
647 spec->subsystem_minor = 0;
648 spec->entry_points = NULL;
649 spec->names = NULL;
650 spec->ordinals = NULL;
651 spec->resources = NULL;
652 return spec;
656 /*******************************************************************
657 * free_dll_spec
659 * Free dll spec file descriptor
661 void free_dll_spec( DLLSPEC *spec )
663 int i;
665 for (i = 0; i < spec->nb_entry_points; i++)
667 ORDDEF *odp = &spec->entry_points[i];
668 free( odp->name );
669 free( odp->export_name );
670 free( odp->link_name );
672 free( spec->file_name );
673 free( spec->dll_name );
674 free( spec->init_func );
675 free( spec->entry_points );
676 free( spec->names );
677 free( spec->ordinals );
678 free( spec->resources );
679 free( spec );
683 /*******************************************************************
684 * make_c_identifier
686 * Map a string to a valid C identifier.
688 const char *make_c_identifier( const char *str )
690 static char buffer[256];
691 char *p;
693 for (p = buffer; *str && p < buffer+sizeof(buffer)-1; p++, str++)
695 if (isalnum(*str)) *p = *str;
696 else *p = '_';
698 *p = 0;
699 return buffer;
703 /*******************************************************************
704 * get_stub_name
706 * Generate an internal name for a stub entry point.
708 const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
710 static char buffer[256];
711 if (odp->name || odp->export_name)
713 char *p;
714 sprintf( buffer, "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
715 /* make sure name is a legal C identifier */
716 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
717 if (!*p) return buffer;
719 sprintf( buffer, "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
720 return buffer;
723 /* parse a cpu name and return the corresponding value */
724 enum target_cpu get_cpu_from_name( const char *name )
726 unsigned int i;
728 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
729 if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
730 return -1;
733 /*****************************************************************
734 * Function: get_alignment
736 * Description:
737 * According to the info page for gas, the .align directive behaves
738 * differently on different systems. On some architectures, the
739 * argument of a .align directive is the number of bytes to pad to, so
740 * to align on an 8-byte boundary you'd say
741 * .align 8
742 * On other systems, the argument is "the number of low-order zero bits
743 * that the location counter must have after advancement." So to
744 * align on an 8-byte boundary you'd say
745 * .align 3
747 * The reason gas is written this way is that it's trying to mimick
748 * native assemblers for the various architectures it runs on. gas
749 * provides other directives that work consistently across
750 * architectures, but of course we want to work on all arches with or
751 * without gas. Hence this function.
754 * Parameters:
755 * align -- the number of bytes to align to. Must be a power of 2.
757 unsigned int get_alignment(unsigned int align)
759 unsigned int n;
761 assert( !(align & (align - 1)) );
763 switch(target_cpu)
765 case CPU_x86:
766 case CPU_x86_64:
767 case CPU_SPARC:
768 case CPU_ARM:
769 if (target_platform != PLATFORM_APPLE) return align;
770 /* fall through */
771 case CPU_POWERPC:
772 case CPU_ALPHA:
773 n = 0;
774 while ((1u << n) != align) n++;
775 return n;
777 /* unreached */
778 assert(0);
779 return 0;
782 /* return the page size for the target CPU */
783 unsigned int get_page_size(void)
785 switch(target_cpu)
787 case CPU_x86: return 4096;
788 case CPU_x86_64: return 4096;
789 case CPU_POWERPC: return 4096;
790 case CPU_ARM: return 4096;
791 case CPU_SPARC: return 8192;
792 case CPU_ALPHA: return 8192;
794 /* unreached */
795 assert(0);
796 return 0;
799 /* return the size of a pointer on the target CPU */
800 unsigned int get_ptr_size(void)
802 switch(target_cpu)
804 case CPU_x86:
805 case CPU_POWERPC:
806 case CPU_SPARC:
807 case CPU_ALPHA:
808 case CPU_ARM:
809 return 4;
810 case CPU_x86_64:
811 return 8;
813 /* unreached */
814 assert(0);
815 return 0;
818 /* return the assembly name for a C symbol */
819 const char *asm_name( const char *sym )
821 static char buffer[256];
823 switch (target_platform)
825 case PLATFORM_APPLE:
826 case PLATFORM_WINDOWS:
827 if (sym[0] == '.' && sym[1] == 'L') return sym;
828 buffer[0] = '_';
829 strcpy( buffer + 1, sym );
830 return buffer;
831 default:
832 return sym;
836 /* return an assembly function declaration for a C function name */
837 const char *func_declaration( const char *func )
839 static char buffer[256];
841 switch (target_platform)
843 case PLATFORM_APPLE:
844 return "";
845 case PLATFORM_WINDOWS:
846 sprintf( buffer, ".def _%s; .scl 2; .type 32; .endef", func );
847 break;
848 default:
849 switch(target_cpu)
851 case CPU_ARM:
852 sprintf( buffer, ".type %s,%%function", func );
853 break;
854 default:
855 sprintf( buffer, ".type %s,@function", func );
856 break;
858 break;
860 return buffer;
863 /* output a size declaration for an assembly function */
864 void output_function_size( const char *name )
866 switch (target_platform)
868 case PLATFORM_APPLE:
869 case PLATFORM_WINDOWS:
870 break;
871 default:
872 output( "\t.size %s, .-%s\n", name, name );
873 break;
877 /* output the GNU note for non-exec stack */
878 void output_gnu_stack_note(void)
880 switch (target_platform)
882 case PLATFORM_WINDOWS:
883 case PLATFORM_APPLE:
884 break;
885 default:
886 switch(target_cpu)
888 case CPU_ARM:
889 output( "\t.section .note.GNU-stack,\"\",%%progbits\n" );
890 break;
891 default:
892 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
893 break;
895 break;
899 /* return a global symbol declaration for an assembly symbol */
900 const char *asm_globl( const char *func )
902 static char buffer[256];
904 switch (target_platform)
906 case PLATFORM_APPLE:
907 sprintf( buffer, "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
908 return buffer;
909 case PLATFORM_WINDOWS:
910 sprintf( buffer, "\t.globl _%s\n_%s:", func, func );
911 return buffer;
912 default:
913 sprintf( buffer, "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
914 return buffer;
918 const char *get_asm_ptr_keyword(void)
920 switch(get_ptr_size())
922 case 4: return ".long";
923 case 8: return ".quad";
925 assert(0);
926 return NULL;
929 const char *get_asm_string_keyword(void)
931 switch (target_platform)
933 case PLATFORM_APPLE:
934 return ".asciz";
935 default:
936 return ".string";
940 const char *get_asm_short_keyword(void)
942 switch (target_platform)
944 default: return ".short";
948 const char *get_asm_rodata_section(void)
950 switch (target_platform)
952 case PLATFORM_APPLE: return ".const";
953 default: return ".section .rodata";
957 const char *get_asm_string_section(void)
959 switch (target_platform)
961 case PLATFORM_APPLE: return ".cstring";
962 default: return ".section .rodata";