tools: Take into account the executable extension when looking for tools in the path.
[wine/multimedia.git] / tools / winebuild / utils.c
blobe0cd8bcb9dfde6ea9c520a854d1c6ae22c8e98f7
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 }
63 /* atexit handler to clean tmp files */
64 static void cleanup_tmp_files(void)
66 unsigned int i;
67 for (i = 0; i < MAX_TMP_FILES; i++) if (tmp_files[i]) unlink( tmp_files[i] );
71 void *xmalloc (size_t size)
73 void *res;
75 res = malloc (size ? size : 1);
76 if (res == NULL)
78 fprintf (stderr, "Virtual memory exhausted.\n");
79 exit (1);
81 return res;
84 void *xrealloc (void *ptr, size_t size)
86 void *res = realloc (ptr, size);
87 if (size && res == NULL)
89 fprintf (stderr, "Virtual memory exhausted.\n");
90 exit (1);
92 return res;
95 char *xstrdup( const char *str )
97 char *res = strdup( str );
98 if (!res)
100 fprintf (stderr, "Virtual memory exhausted.\n");
101 exit (1);
103 return res;
106 char *strupper(char *s)
108 char *p;
109 for (p = s; *p; p++) *p = toupper(*p);
110 return s;
113 int strendswith(const char* str, const char* end)
115 int l = strlen(str);
116 int m = strlen(end);
117 return l >= m && strcmp(str + l - m, end) == 0;
120 void fatal_error( const char *msg, ... )
122 va_list valist;
123 va_start( valist, msg );
124 if (input_file_name)
126 fprintf( stderr, "%s:", input_file_name );
127 if (current_line)
128 fprintf( stderr, "%d:", current_line );
129 fputc( ' ', stderr );
131 else fprintf( stderr, "winebuild: " );
132 vfprintf( stderr, msg, valist );
133 va_end( valist );
134 exit(1);
137 void fatal_perror( const char *msg, ... )
139 va_list valist;
140 va_start( valist, msg );
141 if (input_file_name)
143 fprintf( stderr, "%s:", input_file_name );
144 if (current_line)
145 fprintf( stderr, "%d:", current_line );
146 fputc( ' ', stderr );
148 vfprintf( stderr, msg, valist );
149 perror( " " );
150 va_end( valist );
151 exit(1);
154 void error( const char *msg, ... )
156 va_list valist;
157 va_start( valist, msg );
158 if (input_file_name)
160 fprintf( stderr, "%s:", input_file_name );
161 if (current_line)
162 fprintf( stderr, "%d:", current_line );
163 fputc( ' ', stderr );
165 vfprintf( stderr, msg, valist );
166 va_end( valist );
167 nb_errors++;
170 void warning( const char *msg, ... )
172 va_list valist;
174 if (!display_warnings) return;
175 va_start( valist, msg );
176 if (input_file_name)
178 fprintf( stderr, "%s:", input_file_name );
179 if (current_line)
180 fprintf( stderr, "%d:", current_line );
181 fputc( ' ', stderr );
183 fprintf( stderr, "warning: " );
184 vfprintf( stderr, msg, valist );
185 va_end( valist );
188 int output( const char *format, ... )
190 int ret;
191 va_list valist;
193 va_start( valist, format );
194 ret = vfprintf( output_file, format, valist );
195 va_end( valist );
196 if (ret < 0) fatal_perror( "Output error" );
197 return ret;
200 /* find a build tool in the path, trying the various names */
201 static char *find_tool( const char * const *names )
203 static char **dirs;
204 static unsigned int count, maxlen;
206 char *p, *file;
207 unsigned int i, len;
208 struct stat st;
210 if (!dirs)
212 char *path;
214 /* split the path in directories */
216 if (!getenv( "PATH" )) return NULL;
217 path = xstrdup( getenv( "PATH" ));
218 for (p = path, count = 2; *p; p++) if (*p == ':') count++;
219 dirs = xmalloc( count * sizeof(*dirs) );
220 count = 0;
221 dirs[count++] = p = path;
222 while (*p)
224 while (*p && *p != ':') p++;
225 if (!*p) break;
226 *p++ = 0;
227 dirs[count++] = p;
229 for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 );
232 while (*names)
234 len = strlen(*names) + sizeof(EXEEXT) + 1;
235 file = xmalloc( maxlen + len );
237 for (i = 0; i < count; i++)
239 strcpy( file, dirs[i] );
240 p = file + strlen(file);
241 if (p == file) *p++ = '.';
242 if (p[-1] != '/') *p++ = '/';
243 strcpy( p, *names );
244 strcat( p, EXEEXT );
246 if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111)) return file;
248 free( file );
249 names++;
251 return NULL;
254 const char *get_as_command(void)
256 if (!as_command)
258 if (target_alias)
260 as_command = xmalloc( strlen(target_alias) + sizeof("-as") );
261 strcpy( as_command, target_alias );
262 strcat( as_command, "-as" );
264 else
266 static const char * const commands[] = { "gas", "as", NULL };
267 if (!(as_command = find_tool( commands ))) as_command = xstrdup("as");
270 if (force_pointer_size)
272 const char *args = (target_platform == PLATFORM_APPLE) ?
273 ((force_pointer_size == 8) ? " -arch x86_64" : " -arch i386") :
274 ((force_pointer_size == 8) ? " --64" : " --32");
275 as_command = xrealloc( as_command, strlen(as_command) + strlen(args) + 1 );
276 strcat( as_command, args );
279 return as_command;
282 const char *get_ld_command(void)
284 if (!ld_command)
286 if (target_alias)
288 ld_command = xmalloc( strlen(target_alias) + sizeof("-ld") );
289 strcpy( ld_command, target_alias );
290 strcat( ld_command, "-ld" );
292 else
294 static const char * const commands[] = { "ld", "gld", NULL };
295 if (!(ld_command = find_tool( commands ))) ld_command = xstrdup("ld");
298 if (force_pointer_size)
300 const char *args = (target_platform == PLATFORM_APPLE) ?
301 ((force_pointer_size == 8) ? " -arch x86_64" : " -arch i386") :
302 ((force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386");
303 ld_command = xrealloc( ld_command, strlen(ld_command) + strlen(args) + 1 );
304 strcat( ld_command, args );
307 return ld_command;
310 const char *get_nm_command(void)
312 if (!nm_command)
314 if (target_alias)
316 nm_command = xmalloc( strlen(target_alias) + sizeof("-nm") );
317 strcpy( nm_command, target_alias );
318 strcat( nm_command, "-nm" );
320 else
322 static const char * const commands[] = { "nm", "gnm", NULL };
323 if (!(nm_command = find_tool( commands ))) nm_command = xstrdup("nm");
326 return nm_command;
329 const char *get_windres_command(void)
331 static char *windres_command;
333 if (!windres_command)
335 if (target_alias)
337 windres_command = xmalloc( strlen(target_alias) + sizeof("-windres") );
338 strcpy( windres_command, target_alias );
339 strcat( windres_command, "-windres" );
341 else
343 static const char * const commands[] = { "windres", NULL };
344 if (!(windres_command = find_tool( commands ))) windres_command = xstrdup("windres");
347 return windres_command;
350 /* get a name for a temp file, automatically cleaned up on exit */
351 char *get_temp_file_name( const char *prefix, const char *suffix )
353 char *name;
354 const char *ext;
355 int fd;
357 assert( nb_tmp_files < MAX_TMP_FILES );
358 if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
360 if (!prefix || !prefix[0]) prefix = "winebuild";
361 if (!suffix) suffix = "";
362 if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix);
363 name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
364 strcpy( name, "/tmp/" );
365 memcpy( name + 5, prefix, ext - prefix );
366 strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
367 strcat( name, suffix );
369 /* first try without the /tmp/ prefix */
370 if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1)
371 name += 5;
372 else if ((fd = mkstemps( name, strlen(suffix) )) == -1)
373 fatal_error( "could not generate a temp file\n" );
375 close( fd );
376 tmp_files[nb_tmp_files++] = name;
377 return name;
380 /*******************************************************************
381 * buffer management
383 * Function for reading from/writing to a memory buffer.
386 int byte_swapped = 0;
387 const char *input_buffer_filename;
388 const unsigned char *input_buffer;
389 size_t input_buffer_pos;
390 size_t input_buffer_size;
391 unsigned char *output_buffer;
392 size_t output_buffer_pos;
393 size_t output_buffer_size;
395 static void check_output_buffer_space( size_t size )
397 if (output_buffer_pos + size >= output_buffer_size)
399 output_buffer_size = max( output_buffer_size * 2, output_buffer_pos + size );
400 output_buffer = xrealloc( output_buffer, output_buffer_size );
404 void init_input_buffer( const char *file )
406 int fd;
407 struct stat st;
409 if ((fd = open( file, O_RDONLY | O_BINARY )) == -1) fatal_perror( "Cannot open %s", file );
410 if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", file );
411 if (!st.st_size) fatal_error( "%s is an empty file\n", file );
412 #ifdef HAVE_MMAP
413 if ((input_buffer = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
414 #endif
416 unsigned char *buffer = xmalloc( st.st_size );
417 if (read( fd, buffer, st.st_size ) != st.st_size) fatal_error( "Cannot read %s\n", file );
418 input_buffer = buffer;
420 close( fd );
421 input_buffer_filename = xstrdup( file );
422 input_buffer_size = st.st_size;
423 input_buffer_pos = 0;
424 byte_swapped = 0;
427 void init_output_buffer(void)
429 output_buffer_size = 1024;
430 output_buffer_pos = 0;
431 output_buffer = xmalloc( output_buffer_size );
434 void flush_output_buffer(void)
436 if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
437 fatal_error( "Error writing to %s\n", output_file_name );
438 free( output_buffer );
441 unsigned char get_byte(void)
443 if (input_buffer_pos >= input_buffer_size)
444 fatal_error( "%s is a truncated file\n", input_buffer_filename );
445 return input_buffer[input_buffer_pos++];
448 unsigned short get_word(void)
450 unsigned short ret;
452 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
453 fatal_error( "%s is a truncated file\n", input_buffer_filename );
454 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
455 if (byte_swapped) ret = (ret << 8) | (ret >> 8);
456 input_buffer_pos += sizeof(ret);
457 return ret;
460 unsigned int get_dword(void)
462 unsigned int ret;
464 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
465 fatal_error( "%s is a truncated file\n", input_buffer_filename );
466 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
467 if (byte_swapped)
468 ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
469 input_buffer_pos += sizeof(ret);
470 return ret;
473 void put_data( const void *data, size_t size )
475 check_output_buffer_space( size );
476 memcpy( output_buffer + output_buffer_pos, data, size );
477 output_buffer_pos += size;
480 void put_byte( unsigned char val )
482 check_output_buffer_space( 1 );
483 output_buffer[output_buffer_pos++] = val;
486 void put_word( unsigned short val )
488 if (byte_swapped) val = (val << 8) | (val >> 8);
489 put_data( &val, sizeof(val) );
492 void put_dword( unsigned int val )
494 if (byte_swapped)
495 val = ((val << 24) | ((val << 8) & 0x00ff0000) | ((val >> 8) & 0x0000ff00) | (val >> 24));
496 put_data( &val, sizeof(val) );
499 void put_qword( unsigned int val )
501 if (byte_swapped)
503 put_dword( 0 );
504 put_dword( val );
506 else
508 put_dword( val );
509 put_dword( 0 );
513 /* pointer-sized word */
514 void put_pword( unsigned int val )
516 if (get_ptr_size() == 8) put_qword( val );
517 else put_dword( val );
520 void align_output( unsigned int align )
522 size_t size = align - (output_buffer_pos % align);
524 if (size == align) return;
525 check_output_buffer_space( size );
526 memset( output_buffer + output_buffer_pos, 0, size );
527 output_buffer_pos += size;
530 /* output a standard header for generated files */
531 void output_standard_file_header(void)
533 if (spec_file_name)
534 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name );
535 else
536 output( "/* File generated automatically; do not edit! */\n" );
537 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
540 /* dump a byte stream into the assembly code */
541 void dump_bytes( const void *buffer, unsigned int size )
543 unsigned int i;
544 const unsigned char *ptr = buffer;
546 if (!size) return;
547 output( "\t.byte " );
548 for (i = 0; i < size - 1; i++, ptr++)
550 if ((i % 16) == 15) output( "0x%02x\n\t.byte ", *ptr );
551 else output( "0x%02x,", *ptr );
553 output( "0x%02x\n", *ptr );
557 /*******************************************************************
558 * open_input_file
560 * Open a file in the given srcdir and set the input_file_name global variable.
562 FILE *open_input_file( const char *srcdir, const char *name )
564 char *fullname;
565 FILE *file = fopen( name, "r" );
567 if (!file && srcdir)
569 fullname = xmalloc( strlen(srcdir) + strlen(name) + 2 );
570 strcpy( fullname, srcdir );
571 strcat( fullname, "/" );
572 strcat( fullname, name );
573 file = fopen( fullname, "r" );
575 else fullname = xstrdup( name );
577 if (!file) fatal_error( "Cannot open file '%s'\n", fullname );
578 input_file_name = fullname;
579 current_line = 1;
580 return file;
584 /*******************************************************************
585 * close_input_file
587 * Close the current input file (must have been opened with open_input_file).
589 void close_input_file( FILE *file )
591 fclose( file );
592 free( input_file_name );
593 input_file_name = NULL;
594 current_line = 0;
598 /*******************************************************************
599 * remove_stdcall_decoration
601 * Remove a possible @xx suffix from a function name.
602 * Return the numerical value of the suffix, or -1 if none.
604 int remove_stdcall_decoration( char *name )
606 char *p, *end = strrchr( name, '@' );
607 if (!end || !end[1] || end == name) return -1;
608 /* make sure all the rest is digits */
609 for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
610 *end = 0;
611 return atoi( end + 1 );
615 /*******************************************************************
616 * assemble_file
618 * Run a file through the assembler.
620 void assemble_file( const char *src_file, const char *obj_file )
622 const char *prog = get_as_command();
623 char *cmd;
624 int err;
626 cmd = xmalloc( strlen(prog) + strlen(obj_file) + strlen(src_file) + 6 );
627 sprintf( cmd, "%s -o %s %s", prog, obj_file, src_file );
628 if (verbose) fprintf( stderr, "%s\n", cmd );
629 err = system( cmd );
630 if (err) fatal_error( "%s failed with status %d\n", prog, err );
631 free( cmd );
635 /*******************************************************************
636 * alloc_dll_spec
638 * Create a new dll spec file descriptor
640 DLLSPEC *alloc_dll_spec(void)
642 DLLSPEC *spec;
644 spec = xmalloc( sizeof(*spec) );
645 spec->file_name = NULL;
646 spec->dll_name = NULL;
647 spec->init_func = NULL;
648 spec->main_module = NULL;
649 spec->type = SPEC_WIN32;
650 spec->base = MAX_ORDINALS;
651 spec->limit = 0;
652 spec->stack_size = 0;
653 spec->heap_size = 0;
654 spec->nb_entry_points = 0;
655 spec->alloc_entry_points = 0;
656 spec->nb_names = 0;
657 spec->nb_resources = 0;
658 spec->characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
659 if (get_ptr_size() > 4)
660 spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
661 else
662 spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
663 spec->dll_characteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
664 spec->subsystem = 0;
665 spec->subsystem_major = 4;
666 spec->subsystem_minor = 0;
667 spec->entry_points = NULL;
668 spec->names = NULL;
669 spec->ordinals = NULL;
670 spec->resources = NULL;
671 return spec;
675 /*******************************************************************
676 * free_dll_spec
678 * Free dll spec file descriptor
680 void free_dll_spec( DLLSPEC *spec )
682 int i;
684 for (i = 0; i < spec->nb_entry_points; i++)
686 ORDDEF *odp = &spec->entry_points[i];
687 free( odp->name );
688 free( odp->export_name );
689 free( odp->link_name );
691 free( spec->file_name );
692 free( spec->dll_name );
693 free( spec->init_func );
694 free( spec->entry_points );
695 free( spec->names );
696 free( spec->ordinals );
697 free( spec->resources );
698 free( spec );
702 /*******************************************************************
703 * make_c_identifier
705 * Map a string to a valid C identifier.
707 const char *make_c_identifier( const char *str )
709 static char buffer[256];
710 char *p;
712 for (p = buffer; *str && p < buffer+sizeof(buffer)-1; p++, str++)
714 if (isalnum(*str)) *p = *str;
715 else *p = '_';
717 *p = 0;
718 return buffer;
722 /*******************************************************************
723 * get_stub_name
725 * Generate an internal name for a stub entry point.
727 const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
729 static char buffer[256];
730 if (odp->name || odp->export_name)
732 char *p;
733 sprintf( buffer, "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
734 /* make sure name is a legal C identifier */
735 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
736 if (!*p) return buffer;
738 sprintf( buffer, "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
739 return buffer;
742 /* parse a cpu name and return the corresponding value */
743 enum target_cpu get_cpu_from_name( const char *name )
745 unsigned int i;
747 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
748 if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
749 return -1;
752 /*****************************************************************
753 * Function: get_alignment
755 * Description:
756 * According to the info page for gas, the .align directive behaves
757 * differently on different systems. On some architectures, the
758 * argument of a .align directive is the number of bytes to pad to, so
759 * to align on an 8-byte boundary you'd say
760 * .align 8
761 * On other systems, the argument is "the number of low-order zero bits
762 * that the location counter must have after advancement." So to
763 * align on an 8-byte boundary you'd say
764 * .align 3
766 * The reason gas is written this way is that it's trying to mimick
767 * native assemblers for the various architectures it runs on. gas
768 * provides other directives that work consistently across
769 * architectures, but of course we want to work on all arches with or
770 * without gas. Hence this function.
773 * Parameters:
774 * align -- the number of bytes to align to. Must be a power of 2.
776 unsigned int get_alignment(unsigned int align)
778 unsigned int n;
780 assert( !(align & (align - 1)) );
782 switch(target_cpu)
784 case CPU_x86:
785 case CPU_x86_64:
786 case CPU_SPARC:
787 if (target_platform != PLATFORM_APPLE) return align;
788 /* fall through */
789 case CPU_POWERPC:
790 case CPU_ALPHA:
791 n = 0;
792 while ((1u << n) != align) n++;
793 return n;
795 /* unreached */
796 assert(0);
797 return 0;
800 /* return the page size for the target CPU */
801 unsigned int get_page_size(void)
803 switch(target_cpu)
805 case CPU_x86: return 4096;
806 case CPU_x86_64: return 4096;
807 case CPU_POWERPC: return 4096;
808 case CPU_SPARC: return 8192;
809 case CPU_ALPHA: return 8192;
811 /* unreached */
812 assert(0);
813 return 0;
816 /* return the size of a pointer on the target CPU */
817 unsigned int get_ptr_size(void)
819 switch(target_cpu)
821 case CPU_x86:
822 case CPU_POWERPC:
823 case CPU_SPARC:
824 case CPU_ALPHA:
825 return 4;
826 case CPU_x86_64:
827 return 8;
829 /* unreached */
830 assert(0);
831 return 0;
834 /* return the assembly name for a C symbol */
835 const char *asm_name( const char *sym )
837 static char buffer[256];
839 switch (target_platform)
841 case PLATFORM_APPLE:
842 case PLATFORM_WINDOWS:
843 if (sym[0] == '.' && sym[1] == 'L') return sym;
844 buffer[0] = '_';
845 strcpy( buffer + 1, sym );
846 return buffer;
847 default:
848 return sym;
852 /* return an assembly function declaration for a C function name */
853 const char *func_declaration( const char *func )
855 static char buffer[256];
857 switch (target_platform)
859 case PLATFORM_APPLE:
860 return "";
861 case PLATFORM_WINDOWS:
862 sprintf( buffer, ".def _%s; .scl 2; .type 32; .endef", func );
863 break;
864 default:
865 sprintf( buffer, ".type %s,@function", func );
866 break;
868 return buffer;
871 /* output a size declaration for an assembly function */
872 void output_function_size( const char *name )
874 switch (target_platform)
876 case PLATFORM_APPLE:
877 case PLATFORM_WINDOWS:
878 break;
879 default:
880 output( "\t.size %s, .-%s\n", name, name );
881 break;
885 /* output the GNU note for non-exec stack */
886 void output_gnu_stack_note(void)
888 switch (target_platform)
890 case PLATFORM_WINDOWS:
891 case PLATFORM_APPLE:
892 break;
893 default:
894 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
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";