wininet: Allow HTTPREQ_ReadFileEx read more then one data chunk.
[wine.git] / tools / winebuild / utils.c
blob75568d6b2730a1f3fb03c5650bd2db6a69bcc5f0
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 { "amd64", CPU_x86_64 },
58 { "x86_64", CPU_x86_64 },
59 { "sparc", CPU_SPARC },
60 { "alpha", CPU_ALPHA },
61 { "powerpc", CPU_POWERPC },
62 { "arm", CPU_ARM }
65 /* atexit handler to clean tmp files */
66 static void cleanup_tmp_files(void)
68 unsigned int i;
69 for (i = 0; i < MAX_TMP_FILES; i++) if (tmp_files[i]) unlink( tmp_files[i] );
73 void *xmalloc (size_t size)
75 void *res;
77 res = malloc (size ? size : 1);
78 if (res == NULL)
80 fprintf (stderr, "Virtual memory exhausted.\n");
81 exit (1);
83 return res;
86 void *xrealloc (void *ptr, size_t size)
88 void *res = realloc (ptr, size);
89 if (size && res == NULL)
91 fprintf (stderr, "Virtual memory exhausted.\n");
92 exit (1);
94 return res;
97 char *xstrdup( const char *str )
99 char *res = strdup( str );
100 if (!res)
102 fprintf (stderr, "Virtual memory exhausted.\n");
103 exit (1);
105 return res;
108 char *strupper(char *s)
110 char *p;
111 for (p = s; *p; p++) *p = toupper(*p);
112 return s;
115 int strendswith(const char* str, const char* end)
117 int l = strlen(str);
118 int m = strlen(end);
119 return l >= m && strcmp(str + l - m, end) == 0;
122 void fatal_error( const char *msg, ... )
124 va_list valist;
125 va_start( valist, msg );
126 if (input_file_name)
128 fprintf( stderr, "%s:", input_file_name );
129 if (current_line)
130 fprintf( stderr, "%d:", current_line );
131 fputc( ' ', stderr );
133 else fprintf( stderr, "winebuild: " );
134 vfprintf( stderr, msg, valist );
135 va_end( valist );
136 exit(1);
139 void fatal_perror( const char *msg, ... )
141 va_list valist;
142 va_start( valist, msg );
143 if (input_file_name)
145 fprintf( stderr, "%s:", input_file_name );
146 if (current_line)
147 fprintf( stderr, "%d:", current_line );
148 fputc( ' ', stderr );
150 vfprintf( stderr, msg, valist );
151 perror( " " );
152 va_end( valist );
153 exit(1);
156 void error( const char *msg, ... )
158 va_list valist;
159 va_start( valist, msg );
160 if (input_file_name)
162 fprintf( stderr, "%s:", input_file_name );
163 if (current_line)
164 fprintf( stderr, "%d:", current_line );
165 fputc( ' ', stderr );
167 vfprintf( stderr, msg, valist );
168 va_end( valist );
169 nb_errors++;
172 void warning( const char *msg, ... )
174 va_list valist;
176 if (!display_warnings) return;
177 va_start( valist, msg );
178 if (input_file_name)
180 fprintf( stderr, "%s:", input_file_name );
181 if (current_line)
182 fprintf( stderr, "%d:", current_line );
183 fputc( ' ', stderr );
185 fprintf( stderr, "warning: " );
186 vfprintf( stderr, msg, valist );
187 va_end( valist );
190 int output( const char *format, ... )
192 int ret;
193 va_list valist;
195 va_start( valist, format );
196 ret = vfprintf( output_file, format, valist );
197 va_end( valist );
198 if (ret < 0) fatal_perror( "Output error" );
199 return ret;
202 /* find a build tool in the path, trying the various names */
203 char *find_tool( const char *name, const char * const *names )
205 static char **dirs;
206 static unsigned int count, maxlen;
208 char *p, *file;
209 const char *alt_names[2];
210 unsigned int i, len;
211 struct stat st;
213 if (target_alias)
215 file = xmalloc( strlen(target_alias) + strlen(name) + 2 );
216 strcpy( file, target_alias );
217 strcat( file, "-" );
218 strcat( file, name );
219 return file;
222 if (!dirs)
224 char *path;
226 /* split the path in directories */
228 if (!getenv( "PATH" )) return NULL;
229 path = xstrdup( getenv( "PATH" ));
230 for (p = path, count = 2; *p; p++) if (*p == ':') count++;
231 dirs = xmalloc( count * sizeof(*dirs) );
232 count = 0;
233 dirs[count++] = p = path;
234 while (*p)
236 while (*p && *p != ':') p++;
237 if (!*p) break;
238 *p++ = 0;
239 dirs[count++] = p;
241 for (i = 0; i < count; i++) maxlen = max( maxlen, strlen(dirs[i])+2 );
244 if (!names)
246 alt_names[0] = name;
247 alt_names[1] = NULL;
248 names = alt_names;
251 while (*names)
253 len = strlen(*names) + sizeof(EXEEXT) + 1;
254 file = xmalloc( maxlen + len );
256 for (i = 0; i < count; i++)
258 strcpy( file, dirs[i] );
259 p = file + strlen(file);
260 if (p == file) *p++ = '.';
261 if (p[-1] != '/') *p++ = '/';
262 strcpy( p, *names );
263 strcat( p, EXEEXT );
265 if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111)) return file;
267 free( file );
268 names++;
270 return xstrdup( name );
273 const char *get_as_command(void)
275 if (!as_command)
277 static const char * const commands[] = { "gas", "as", NULL };
278 as_command = find_tool( "as", commands );
280 if (force_pointer_size)
282 const char *args = (target_platform == PLATFORM_APPLE) ?
283 ((force_pointer_size == 8) ? " -arch x86_64" : " -arch i386") :
284 ((force_pointer_size == 8) ? " --64" : " --32");
285 as_command = xrealloc( as_command, strlen(as_command) + strlen(args) + 1 );
286 strcat( as_command, args );
289 return as_command;
292 const char *get_ld_command(void)
294 if (!ld_command)
296 static const char * const commands[] = { "ld", "gld", NULL };
297 ld_command = find_tool( "ld", commands );
299 if (force_pointer_size)
301 const char *args;
303 switch (target_platform)
305 case PLATFORM_APPLE:
306 args = (force_pointer_size == 8) ? " -arch x86_64" : " -arch i386";
307 break;
308 case PLATFORM_FREEBSD:
309 args = (force_pointer_size == 8) ? " -m elf_x86_64_fbsd" : " -m elf_i386_fbsd";
310 break;
311 default:
312 args = (force_pointer_size == 8) ? " -m elf_x86_64" : " -m elf_i386";
313 break;
315 ld_command = xrealloc( ld_command, strlen(ld_command) + strlen(args) + 1 );
316 strcat( ld_command, args );
319 return ld_command;
322 const char *get_nm_command(void)
324 if (!nm_command)
326 static const char * const commands[] = { "nm", "gnm", NULL };
327 nm_command = find_tool( "nm", commands );
329 return nm_command;
332 /* get a name for a temp file, automatically cleaned up on exit */
333 char *get_temp_file_name( const char *prefix, const char *suffix )
335 char *name;
336 const char *ext;
337 int fd;
339 assert( nb_tmp_files < MAX_TMP_FILES );
340 if (!nb_tmp_files && !save_temps) atexit( cleanup_tmp_files );
342 if (!prefix || !prefix[0]) prefix = "winebuild";
343 if (!suffix) suffix = "";
344 if (!(ext = strchr( prefix, '.' ))) ext = prefix + strlen(prefix);
345 name = xmalloc( sizeof("/tmp/") + (ext - prefix) + sizeof(".XXXXXX") + strlen(suffix) );
346 strcpy( name, "/tmp/" );
347 memcpy( name + 5, prefix, ext - prefix );
348 strcpy( name + 5 + (ext - prefix), ".XXXXXX" );
349 strcat( name, suffix );
351 /* first try without the /tmp/ prefix */
352 if ((fd = mkstemps( name + 5, strlen(suffix) )) != -1)
353 name += 5;
354 else if ((fd = mkstemps( name, strlen(suffix) )) == -1)
355 fatal_error( "could not generate a temp file\n" );
357 close( fd );
358 tmp_files[nb_tmp_files++] = name;
359 return name;
362 /*******************************************************************
363 * buffer management
365 * Function for reading from/writing to a memory buffer.
368 int byte_swapped = 0;
369 const char *input_buffer_filename;
370 const unsigned char *input_buffer;
371 size_t input_buffer_pos;
372 size_t input_buffer_size;
373 unsigned char *output_buffer;
374 size_t output_buffer_pos;
375 size_t output_buffer_size;
377 static void check_output_buffer_space( size_t size )
379 if (output_buffer_pos + size >= output_buffer_size)
381 output_buffer_size = max( output_buffer_size * 2, output_buffer_pos + size );
382 output_buffer = xrealloc( output_buffer, output_buffer_size );
386 void init_input_buffer( const char *file )
388 int fd;
389 struct stat st;
391 if ((fd = open( file, O_RDONLY | O_BINARY )) == -1) fatal_perror( "Cannot open %s", file );
392 if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", file );
393 if (!st.st_size) fatal_error( "%s is an empty file\n", file );
394 #ifdef HAVE_MMAP
395 if ((input_buffer = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
396 #endif
398 unsigned char *buffer = xmalloc( st.st_size );
399 if (read( fd, buffer, st.st_size ) != st.st_size) fatal_error( "Cannot read %s\n", file );
400 input_buffer = buffer;
402 close( fd );
403 input_buffer_filename = xstrdup( file );
404 input_buffer_size = st.st_size;
405 input_buffer_pos = 0;
406 byte_swapped = 0;
409 void init_output_buffer(void)
411 output_buffer_size = 1024;
412 output_buffer_pos = 0;
413 output_buffer = xmalloc( output_buffer_size );
416 void flush_output_buffer(void)
418 if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
419 fatal_error( "Error writing to %s\n", output_file_name );
420 free( output_buffer );
423 unsigned char get_byte(void)
425 if (input_buffer_pos >= input_buffer_size)
426 fatal_error( "%s is a truncated file\n", input_buffer_filename );
427 return input_buffer[input_buffer_pos++];
430 unsigned short get_word(void)
432 unsigned short ret;
434 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
435 fatal_error( "%s is a truncated file\n", input_buffer_filename );
436 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
437 if (byte_swapped) ret = (ret << 8) | (ret >> 8);
438 input_buffer_pos += sizeof(ret);
439 return ret;
442 unsigned int get_dword(void)
444 unsigned int ret;
446 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
447 fatal_error( "%s is a truncated file\n", input_buffer_filename );
448 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
449 if (byte_swapped)
450 ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
451 input_buffer_pos += sizeof(ret);
452 return ret;
455 void put_data( const void *data, size_t size )
457 check_output_buffer_space( size );
458 memcpy( output_buffer + output_buffer_pos, data, size );
459 output_buffer_pos += size;
462 void put_byte( unsigned char val )
464 check_output_buffer_space( 1 );
465 output_buffer[output_buffer_pos++] = val;
468 void put_word( unsigned short val )
470 if (byte_swapped) val = (val << 8) | (val >> 8);
471 put_data( &val, sizeof(val) );
474 void put_dword( unsigned int val )
476 if (byte_swapped)
477 val = ((val << 24) | ((val << 8) & 0x00ff0000) | ((val >> 8) & 0x0000ff00) | (val >> 24));
478 put_data( &val, sizeof(val) );
481 void put_qword( unsigned int val )
483 if (byte_swapped)
485 put_dword( 0 );
486 put_dword( val );
488 else
490 put_dword( val );
491 put_dword( 0 );
495 /* pointer-sized word */
496 void put_pword( unsigned int val )
498 if (get_ptr_size() == 8) put_qword( val );
499 else put_dword( val );
502 void align_output( unsigned int align )
504 size_t size = align - (output_buffer_pos % align);
506 if (size == align) return;
507 check_output_buffer_space( size );
508 memset( output_buffer + output_buffer_pos, 0, size );
509 output_buffer_pos += size;
512 /* output a standard header for generated files */
513 void output_standard_file_header(void)
515 if (spec_file_name)
516 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name );
517 else
518 output( "/* File generated automatically; do not edit! */\n" );
519 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
522 /* dump a byte stream into the assembly code */
523 void dump_bytes( const void *buffer, unsigned int size )
525 unsigned int i;
526 const unsigned char *ptr = buffer;
528 if (!size) return;
529 output( "\t.byte " );
530 for (i = 0; i < size - 1; i++, ptr++)
532 if ((i % 16) == 15) output( "0x%02x\n\t.byte ", *ptr );
533 else output( "0x%02x,", *ptr );
535 output( "0x%02x\n", *ptr );
539 /*******************************************************************
540 * open_input_file
542 * Open a file in the given srcdir and set the input_file_name global variable.
544 FILE *open_input_file( const char *srcdir, const char *name )
546 char *fullname;
547 FILE *file = fopen( name, "r" );
549 if (!file && srcdir)
551 fullname = xmalloc( strlen(srcdir) + strlen(name) + 2 );
552 strcpy( fullname, srcdir );
553 strcat( fullname, "/" );
554 strcat( fullname, name );
555 file = fopen( fullname, "r" );
557 else fullname = xstrdup( name );
559 if (!file) fatal_error( "Cannot open file '%s'\n", fullname );
560 input_file_name = fullname;
561 current_line = 1;
562 return file;
566 /*******************************************************************
567 * close_input_file
569 * Close the current input file (must have been opened with open_input_file).
571 void close_input_file( FILE *file )
573 fclose( file );
574 free( input_file_name );
575 input_file_name = NULL;
576 current_line = 0;
580 /*******************************************************************
581 * remove_stdcall_decoration
583 * Remove a possible @xx suffix from a function name.
584 * Return the numerical value of the suffix, or -1 if none.
586 int remove_stdcall_decoration( char *name )
588 char *p, *end = strrchr( name, '@' );
589 if (!end || !end[1] || end == name) return -1;
590 /* make sure all the rest is digits */
591 for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
592 *end = 0;
593 return atoi( end + 1 );
597 /*******************************************************************
598 * assemble_file
600 * Run a file through the assembler.
602 void assemble_file( const char *src_file, const char *obj_file )
604 const char *prog = get_as_command();
605 char *cmd;
606 int err;
608 cmd = xmalloc( strlen(prog) + strlen(obj_file) + strlen(src_file) + 6 );
609 sprintf( cmd, "%s -o %s %s", prog, obj_file, src_file );
610 if (verbose) fprintf( stderr, "%s\n", cmd );
611 err = system( cmd );
612 if (err) fatal_error( "%s failed with status %d\n", prog, err );
613 free( cmd );
617 /*******************************************************************
618 * alloc_dll_spec
620 * Create a new dll spec file descriptor
622 DLLSPEC *alloc_dll_spec(void)
624 DLLSPEC *spec;
626 spec = xmalloc( sizeof(*spec) );
627 spec->file_name = NULL;
628 spec->dll_name = NULL;
629 spec->init_func = NULL;
630 spec->main_module = NULL;
631 spec->type = SPEC_WIN32;
632 spec->base = MAX_ORDINALS;
633 spec->limit = 0;
634 spec->stack_size = 0;
635 spec->heap_size = 0;
636 spec->nb_entry_points = 0;
637 spec->alloc_entry_points = 0;
638 spec->nb_names = 0;
639 spec->nb_resources = 0;
640 spec->characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
641 if (get_ptr_size() > 4)
642 spec->characteristics |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
643 else
644 spec->characteristics |= IMAGE_FILE_32BIT_MACHINE;
645 spec->dll_characteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
646 spec->subsystem = 0;
647 spec->subsystem_major = 4;
648 spec->subsystem_minor = 0;
649 spec->entry_points = NULL;
650 spec->names = NULL;
651 spec->ordinals = NULL;
652 spec->resources = NULL;
653 return spec;
657 /*******************************************************************
658 * free_dll_spec
660 * Free dll spec file descriptor
662 void free_dll_spec( DLLSPEC *spec )
664 int i;
666 for (i = 0; i < spec->nb_entry_points; i++)
668 ORDDEF *odp = &spec->entry_points[i];
669 free( odp->name );
670 free( odp->export_name );
671 free( odp->link_name );
673 free( spec->file_name );
674 free( spec->dll_name );
675 free( spec->init_func );
676 free( spec->entry_points );
677 free( spec->names );
678 free( spec->ordinals );
679 free( spec->resources );
680 free( spec );
684 /*******************************************************************
685 * make_c_identifier
687 * Map a string to a valid C identifier.
689 const char *make_c_identifier( const char *str )
691 static char buffer[256];
692 char *p;
694 for (p = buffer; *str && p < buffer+sizeof(buffer)-1; p++, str++)
696 if (isalnum(*str)) *p = *str;
697 else *p = '_';
699 *p = 0;
700 return buffer;
704 /*******************************************************************
705 * get_stub_name
707 * Generate an internal name for a stub entry point.
709 const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
711 static char buffer[256];
712 if (odp->name || odp->export_name)
714 char *p;
715 sprintf( buffer, "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
716 /* make sure name is a legal C identifier */
717 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
718 if (!*p) return buffer;
720 sprintf( buffer, "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
721 return buffer;
724 /* parse a cpu name and return the corresponding value */
725 enum target_cpu get_cpu_from_name( const char *name )
727 unsigned int i;
729 for (i = 0; i < sizeof(cpu_names)/sizeof(cpu_names[0]); i++)
730 if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
731 return -1;
734 /*****************************************************************
735 * Function: get_alignment
737 * Description:
738 * According to the info page for gas, the .align directive behaves
739 * differently on different systems. On some architectures, the
740 * argument of a .align directive is the number of bytes to pad to, so
741 * to align on an 8-byte boundary you'd say
742 * .align 8
743 * On other systems, the argument is "the number of low-order zero bits
744 * that the location counter must have after advancement." So to
745 * align on an 8-byte boundary you'd say
746 * .align 3
748 * The reason gas is written this way is that it's trying to mimick
749 * native assemblers for the various architectures it runs on. gas
750 * provides other directives that work consistently across
751 * architectures, but of course we want to work on all arches with or
752 * without gas. Hence this function.
755 * Parameters:
756 * align -- the number of bytes to align to. Must be a power of 2.
758 unsigned int get_alignment(unsigned int align)
760 unsigned int n;
762 assert( !(align & (align - 1)) );
764 switch(target_cpu)
766 case CPU_x86:
767 case CPU_x86_64:
768 case CPU_SPARC:
769 case CPU_ARM:
770 if (target_platform != PLATFORM_APPLE) return align;
771 /* fall through */
772 case CPU_POWERPC:
773 case CPU_ALPHA:
774 n = 0;
775 while ((1u << n) != align) n++;
776 return n;
778 /* unreached */
779 assert(0);
780 return 0;
783 /* return the page size for the target CPU */
784 unsigned int get_page_size(void)
786 switch(target_cpu)
788 case CPU_x86: return 4096;
789 case CPU_x86_64: return 4096;
790 case CPU_POWERPC: return 4096;
791 case CPU_ARM: return 4096;
792 case CPU_SPARC: return 8192;
793 case CPU_ALPHA: return 8192;
795 /* unreached */
796 assert(0);
797 return 0;
800 /* return the size of a pointer on the target CPU */
801 unsigned int get_ptr_size(void)
803 switch(target_cpu)
805 case CPU_x86:
806 case CPU_POWERPC:
807 case CPU_SPARC:
808 case CPU_ALPHA:
809 case CPU_ARM:
810 return 4;
811 case CPU_x86_64:
812 return 8;
814 /* unreached */
815 assert(0);
816 return 0;
819 /* return the assembly name for a C symbol */
820 const char *asm_name( const char *sym )
822 static char buffer[256];
824 switch (target_platform)
826 case PLATFORM_APPLE:
827 case PLATFORM_WINDOWS:
828 if (sym[0] == '.' && sym[1] == 'L') return sym;
829 buffer[0] = '_';
830 strcpy( buffer + 1, sym );
831 return buffer;
832 default:
833 return sym;
837 /* return an assembly function declaration for a C function name */
838 const char *func_declaration( const char *func )
840 static char buffer[256];
842 switch (target_platform)
844 case PLATFORM_APPLE:
845 return "";
846 case PLATFORM_WINDOWS:
847 sprintf( buffer, ".def _%s; .scl 2; .type 32; .endef", func );
848 break;
849 default:
850 switch(target_cpu)
852 case CPU_ARM:
853 sprintf( buffer, ".type %s,%%function", func );
854 break;
855 default:
856 sprintf( buffer, ".type %s,@function", func );
857 break;
859 break;
861 return buffer;
864 /* output a size declaration for an assembly function */
865 void output_function_size( const char *name )
867 switch (target_platform)
869 case PLATFORM_APPLE:
870 case PLATFORM_WINDOWS:
871 break;
872 default:
873 output( "\t.size %s, .-%s\n", name, name );
874 break;
878 /* output a .cfi directive */
879 void output_cfi( const char *format, ... )
881 va_list valist;
883 if (!unwind_tables) return;
884 va_start( valist, format );
885 fputc( '\t', output_file );
886 vfprintf( output_file, format, valist );
887 fputc( '\n', output_file );
888 va_end( valist );
891 /* output the GNU note for non-exec stack */
892 void output_gnu_stack_note(void)
894 switch (target_platform)
896 case PLATFORM_WINDOWS:
897 case PLATFORM_APPLE:
898 break;
899 default:
900 switch(target_cpu)
902 case CPU_ARM:
903 output( "\t.section .note.GNU-stack,\"\",%%progbits\n" );
904 break;
905 default:
906 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
907 break;
909 break;
913 /* return a global symbol declaration for an assembly symbol */
914 const char *asm_globl( const char *func )
916 static char buffer[256];
918 switch (target_platform)
920 case PLATFORM_APPLE:
921 sprintf( buffer, "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
922 return buffer;
923 case PLATFORM_WINDOWS:
924 sprintf( buffer, "\t.globl _%s\n_%s:", func, func );
925 return buffer;
926 default:
927 sprintf( buffer, "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
928 return buffer;
932 const char *get_asm_ptr_keyword(void)
934 switch(get_ptr_size())
936 case 4: return ".long";
937 case 8: return ".quad";
939 assert(0);
940 return NULL;
943 const char *get_asm_string_keyword(void)
945 switch (target_platform)
947 case PLATFORM_APPLE:
948 return ".asciz";
949 default:
950 return ".string";
954 const char *get_asm_short_keyword(void)
956 switch (target_platform)
958 default: return ".short";
962 const char *get_asm_rodata_section(void)
964 switch (target_platform)
966 case PLATFORM_APPLE: return ".const";
967 default: return ".section .rodata";
971 const char *get_asm_string_section(void)
973 switch (target_platform)
975 case PLATFORM_APPLE: return ".cstring";
976 default: return ".section .rodata";