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
22 #include "wine/port.h"
33 #ifdef HAVE_SYS_STAT_H
34 # include <sys/stat.h>
36 #ifdef HAVE_SYS_MMAN_H
42 static const char **tmp_files
;
43 static unsigned int nb_tmp_files
;
44 static unsigned int max_tmp_files
;
57 { "amd64", CPU_x86_64
},
58 { "x86_64", CPU_x86_64
},
59 { "powerpc", CPU_POWERPC
},
61 { "arm64", CPU_ARM64
},
62 { "aarch64", CPU_ARM64
},
65 /* atexit handler to clean tmp files */
66 void cleanup_tmp_files(void)
69 for (i
= 0; i
< nb_tmp_files
; i
++) if (tmp_files
[i
]) unlink( tmp_files
[i
] );
73 void *xmalloc (size_t size
)
77 res
= malloc (size
? size
: 1);
80 fprintf (stderr
, "Virtual memory exhausted.\n");
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");
97 char *xstrdup( const char *str
)
99 char *res
= strdup( str
);
102 fprintf (stderr
, "Virtual memory exhausted.\n");
108 char *strupper(char *s
)
111 for (p
= s
; *p
; p
++) *p
= toupper(*p
);
115 int strendswith(const char* str
, const char* end
)
119 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
122 char *strmake( const char* fmt
, ... )
130 char *p
= xmalloc( size
);
132 n
= vsnprintf( p
, size
, fmt
, ap
);
134 if (n
== -1) size
*= 2;
135 else if ((size_t)n
>= size
) size
= n
+ 1;
141 static struct strarray
*strarray_init( const char *str
)
143 struct strarray
*array
= xmalloc( sizeof(*array
) );
146 array
->str
= xmalloc( array
->max
* sizeof(*array
->str
) );
147 if (str
) array
->str
[array
->count
++] = str
;
151 static struct strarray
*strarray_copy( const struct strarray
*src
)
153 struct strarray
*array
= xmalloc( sizeof(*array
) );
154 array
->count
= src
->count
;
155 array
->max
= src
->max
;
156 array
->str
= xmalloc( array
->max
* sizeof(*array
->str
) );
157 memcpy( array
->str
, src
->str
, array
->count
* sizeof(*array
->str
) );
161 static void strarray_add_one( struct strarray
*array
, const char *str
)
163 if (array
->count
== array
->max
)
166 array
->str
= xrealloc( array
->str
, array
->max
* sizeof(*array
->str
) );
168 array
->str
[array
->count
++] = str
;
171 void strarray_add( struct strarray
*array
, ... )
176 va_start( valist
, array
);
177 while ((str
= va_arg( valist
, const char *))) strarray_add_one( array
, str
);
181 void strarray_addv( struct strarray
*array
, char * const *argv
)
183 while (*argv
) strarray_add_one( array
, *argv
++ );
186 struct strarray
*strarray_fromstring( const char *str
, const char *delim
)
189 struct strarray
*array
= strarray_init( NULL
);
190 char *buf
= strdup( str
);
192 for (tok
= strtok( buf
, delim
); tok
; tok
= strtok( NULL
, delim
))
193 strarray_add_one( array
, strdup( tok
));
199 void strarray_free( struct strarray
*array
)
205 void fatal_error( const char *msg
, ... )
208 va_start( valist
, msg
);
211 fprintf( stderr
, "%s:", input_file_name
);
213 fprintf( stderr
, "%d:", current_line
);
214 fputc( ' ', stderr
);
216 else fprintf( stderr
, "winebuild: " );
217 vfprintf( stderr
, msg
, valist
);
222 void fatal_perror( const char *msg
, ... )
225 va_start( valist
, msg
);
228 fprintf( stderr
, "%s:", input_file_name
);
230 fprintf( stderr
, "%d:", current_line
);
231 fputc( ' ', stderr
);
233 vfprintf( stderr
, msg
, valist
);
239 void error( const char *msg
, ... )
242 va_start( valist
, msg
);
245 fprintf( stderr
, "%s:", input_file_name
);
247 fprintf( stderr
, "%d:", current_line
);
248 fputc( ' ', stderr
);
250 vfprintf( stderr
, msg
, valist
);
255 void warning( const char *msg
, ... )
259 if (!display_warnings
) return;
260 va_start( valist
, msg
);
263 fprintf( stderr
, "%s:", input_file_name
);
265 fprintf( stderr
, "%d:", current_line
);
266 fputc( ' ', stderr
);
268 fprintf( stderr
, "warning: " );
269 vfprintf( stderr
, msg
, valist
);
273 int output( const char *format
, ... )
278 va_start( valist
, format
);
279 ret
= vfprintf( output_file
, format
, valist
);
281 if (ret
< 0) fatal_perror( "Output error" );
285 void spawn( struct strarray
*args
)
290 strarray_add_one( args
, NULL
);
292 for (i
= 0; args
->str
[i
]; i
++)
293 fprintf( stderr
, "%s%c", args
->str
[i
], args
->str
[i
+1] ? ' ' : '\n' );
295 if ((status
= _spawnvp( _P_WAIT
, args
->str
[0], args
->str
)))
297 if (status
> 0) fatal_error( "%s failed with status %u\n", args
->str
[0], status
);
298 else fatal_perror( "winebuild" );
303 /* find a build tool in the path, trying the various names */
304 struct strarray
*find_tool( const char *name
, const char * const *names
)
307 static unsigned int count
, maxlen
;
310 const char *alt_names
[2];
318 /* split the path in directories */
320 if (!getenv( "PATH" )) return NULL
;
321 path
= xstrdup( getenv( "PATH" ));
322 for (p
= path
, count
= 2; *p
; p
++) if (*p
== ':') count
++;
323 dirs
= xmalloc( count
* sizeof(*dirs
) );
325 dirs
[count
++] = p
= path
;
328 while (*p
&& *p
!= ':') p
++;
333 for (i
= 0; i
< count
; i
++) maxlen
= max( maxlen
, strlen(dirs
[i
])+2 );
345 len
= strlen(*names
) + sizeof(EXEEXT
) + 1;
347 len
+= strlen(target_alias
) + 1;
348 file
= xmalloc( maxlen
+ len
);
350 for (i
= 0; i
< count
; i
++)
352 strcpy( file
, dirs
[i
] );
353 p
= file
+ strlen(file
);
354 if (p
== file
) *p
++ = '.';
355 if (p
[-1] != '/') *p
++ = '/';
358 strcpy( p
, target_alias
);
365 if (!stat( file
, &st
) && S_ISREG(st
.st_mode
) && (st
.st_mode
& 0111))
366 return strarray_init( file
);
374 struct strarray
*get_as_command(void)
376 struct strarray
*args
;
380 args
= strarray_copy( cc_command
);
381 strarray_add( args
, "-xassembler", "-c", NULL
);
382 if (force_pointer_size
)
383 strarray_add_one( args
, (force_pointer_size
== 8) ? "-m64" : "-m32" );
384 if (cpu_option
) strarray_add_one( args
, strmake("-mcpu=%s", cpu_option
) );
390 static const char * const commands
[] = { "gas", "as", NULL
};
391 as_command
= find_tool( "as", commands
);
395 fatal_error( "cannot find suitable assembler\n" );
397 args
= strarray_copy( as_command
);
399 if (force_pointer_size
)
401 switch (target_platform
)
404 strarray_add( args
, "-arch", (force_pointer_size
== 8) ? "x86_64" : "i386", NULL
);
410 strarray_add_one( args
, (force_pointer_size
== 8) ? "-a64" : "-a32" );
413 strarray_add_one( args
, (force_pointer_size
== 8) ? "--64" : "--32" );
420 if (cpu_option
) strarray_add_one( args
, strmake("-mcpu=%s", cpu_option
) );
424 struct strarray
*get_ld_command(void)
426 struct strarray
*args
;
430 static const char * const commands
[] = { "ld", "gld", NULL
};
431 ld_command
= find_tool( "ld", commands
);
435 fatal_error( "cannot find suitable linker\n" );
437 args
= strarray_copy( ld_command
);
439 if (force_pointer_size
)
441 switch (target_platform
)
444 strarray_add( args
, "-arch", (force_pointer_size
== 8) ? "x86_64" : "i386", NULL
);
446 case PLATFORM_FREEBSD
:
447 strarray_add( args
, "-m", (force_pointer_size
== 8) ? "elf_x86_64_fbsd" : "elf_i386_fbsd", NULL
);
453 strarray_add( args
, "-m", (force_pointer_size
== 8) ? "elf64ppc" : "elf32ppc", NULL
);
456 strarray_add( args
, "-m", (force_pointer_size
== 8) ? "elf_x86_64" : "elf_i386", NULL
);
465 const char *get_nm_command(void)
469 static const char * const commands
[] = { "nm", "gnm", NULL
};
470 nm_command
= find_tool( "nm", commands
);
474 fatal_error( "cannot find suitable name lister\n" );
475 if (nm_command
->count
> 1)
476 fatal_error( "multiple arguments in nm command not supported yet\n" );
477 return nm_command
->str
[0];
480 /* get a name for a temp file, automatically cleaned up on exit */
481 char *get_temp_file_name( const char *prefix
, const char *suffix
)
484 const char *ext
, *basename
;
487 if (!prefix
|| !prefix
[0]) prefix
= "winebuild";
488 if (!suffix
) suffix
= "";
489 if ((basename
= strrchr( prefix
, '/' ))) basename
++;
490 else basename
= prefix
;
491 if (!(ext
= strchr( basename
, '.' ))) ext
= prefix
+ strlen(prefix
);
492 name
= xmalloc( sizeof("/tmp/") + (ext
- prefix
) + sizeof(".XXXXXX") + strlen(suffix
) );
493 memcpy( name
, prefix
, ext
- prefix
);
494 strcpy( name
+ (ext
- prefix
), ".XXXXXX" );
495 strcat( name
, suffix
);
497 if ((fd
= mkstemps( name
, strlen(suffix
) )) == -1)
499 strcpy( name
, "/tmp/" );
500 memcpy( name
+ 5, basename
, ext
- basename
);
501 strcpy( name
+ 5 + (ext
- basename
), ".XXXXXX" );
502 strcat( name
, suffix
);
503 if ((fd
= mkstemps( name
, strlen(suffix
) )) == -1)
504 fatal_error( "could not generate a temp file\n" );
508 if (nb_tmp_files
>= max_tmp_files
)
510 max_tmp_files
= max( 2 * max_tmp_files
, 8 );
511 tmp_files
= xrealloc( tmp_files
, max_tmp_files
* sizeof(tmp_files
[0]) );
513 tmp_files
[nb_tmp_files
++] = name
;
517 /*******************************************************************
520 * Function for reading from/writing to a memory buffer.
523 int byte_swapped
= 0;
524 const char *input_buffer_filename
;
525 const unsigned char *input_buffer
;
526 size_t input_buffer_pos
;
527 size_t input_buffer_size
;
528 unsigned char *output_buffer
;
529 size_t output_buffer_pos
;
530 size_t output_buffer_size
;
532 static void check_output_buffer_space( size_t size
)
534 if (output_buffer_pos
+ size
>= output_buffer_size
)
536 output_buffer_size
= max( output_buffer_size
* 2, output_buffer_pos
+ size
);
537 output_buffer
= xrealloc( output_buffer
, output_buffer_size
);
541 void init_input_buffer( const char *file
)
546 if ((fd
= open( file
, O_RDONLY
| O_BINARY
)) == -1) fatal_perror( "Cannot open %s", file
);
547 if ((fstat( fd
, &st
) == -1)) fatal_perror( "Cannot stat %s", file
);
548 if (!st
.st_size
) fatal_error( "%s is an empty file\n", file
);
550 if ((input_buffer
= mmap( NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0 )) == (void*)-1)
553 unsigned char *buffer
= xmalloc( st
.st_size
);
554 if (read( fd
, buffer
, st
.st_size
) != st
.st_size
) fatal_error( "Cannot read %s\n", file
);
555 input_buffer
= buffer
;
558 input_buffer_filename
= xstrdup( file
);
559 input_buffer_size
= st
.st_size
;
560 input_buffer_pos
= 0;
564 void init_output_buffer(void)
566 output_buffer_size
= 1024;
567 output_buffer_pos
= 0;
568 output_buffer
= xmalloc( output_buffer_size
);
571 void flush_output_buffer(void)
573 if (fwrite( output_buffer
, 1, output_buffer_pos
, output_file
) != output_buffer_pos
)
574 fatal_error( "Error writing to %s\n", output_file_name
);
575 free( output_buffer
);
578 unsigned char get_byte(void)
580 if (input_buffer_pos
>= input_buffer_size
)
581 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
582 return input_buffer
[input_buffer_pos
++];
585 unsigned short get_word(void)
589 if (input_buffer_pos
+ sizeof(ret
) > input_buffer_size
)
590 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
591 memcpy( &ret
, input_buffer
+ input_buffer_pos
, sizeof(ret
) );
592 if (byte_swapped
) ret
= (ret
<< 8) | (ret
>> 8);
593 input_buffer_pos
+= sizeof(ret
);
597 unsigned int get_dword(void)
601 if (input_buffer_pos
+ sizeof(ret
) > input_buffer_size
)
602 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
603 memcpy( &ret
, input_buffer
+ input_buffer_pos
, sizeof(ret
) );
605 ret
= ((ret
<< 24) | ((ret
<< 8) & 0x00ff0000) | ((ret
>> 8) & 0x0000ff00) | (ret
>> 24));
606 input_buffer_pos
+= sizeof(ret
);
610 void put_data( const void *data
, size_t size
)
612 check_output_buffer_space( size
);
613 memcpy( output_buffer
+ output_buffer_pos
, data
, size
);
614 output_buffer_pos
+= size
;
617 void put_byte( unsigned char val
)
619 check_output_buffer_space( 1 );
620 output_buffer
[output_buffer_pos
++] = val
;
623 void put_word( unsigned short val
)
625 if (byte_swapped
) val
= (val
<< 8) | (val
>> 8);
626 put_data( &val
, sizeof(val
) );
629 void put_dword( unsigned int val
)
632 val
= ((val
<< 24) | ((val
<< 8) & 0x00ff0000) | ((val
>> 8) & 0x0000ff00) | (val
>> 24));
633 put_data( &val
, sizeof(val
) );
636 void put_qword( unsigned int val
)
650 /* pointer-sized word */
651 void put_pword( unsigned int val
)
653 if (get_ptr_size() == 8) put_qword( val
);
654 else put_dword( val
);
657 void align_output( unsigned int align
)
659 size_t size
= align
- (output_buffer_pos
% align
);
661 if (size
== align
) return;
662 check_output_buffer_space( size
);
663 memset( output_buffer
+ output_buffer_pos
, 0, size
);
664 output_buffer_pos
+= size
;
667 /* output a standard header for generated files */
668 void output_standard_file_header(void)
671 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name
);
673 output( "/* File generated automatically; do not edit! */\n" );
674 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
677 /* dump a byte stream into the assembly code */
678 void dump_bytes( const void *buffer
, unsigned int size
)
681 const unsigned char *ptr
= buffer
;
684 output( "\t.byte " );
685 for (i
= 0; i
< size
- 1; i
++, ptr
++)
687 if ((i
% 16) == 15) output( "0x%02x\n\t.byte ", *ptr
);
688 else output( "0x%02x,", *ptr
);
690 output( "0x%02x\n", *ptr
);
694 /*******************************************************************
697 * Open a file in the given srcdir and set the input_file_name global variable.
699 FILE *open_input_file( const char *srcdir
, const char *name
)
702 FILE *file
= fopen( name
, "r" );
706 fullname
= strmake( "%s/%s", srcdir
, name
);
707 file
= fopen( fullname
, "r" );
709 else fullname
= xstrdup( name
);
711 if (!file
) fatal_error( "Cannot open file '%s'\n", fullname
);
712 input_file_name
= fullname
;
718 /*******************************************************************
721 * Close the current input file (must have been opened with open_input_file).
723 void close_input_file( FILE *file
)
726 free( input_file_name
);
727 input_file_name
= NULL
;
732 /*******************************************************************
733 * remove_stdcall_decoration
735 * Remove a possible @xx suffix from a function name.
736 * Return the numerical value of the suffix, or -1 if none.
738 int remove_stdcall_decoration( char *name
)
740 char *p
, *end
= strrchr( name
, '@' );
741 if (!end
|| !end
[1] || end
== name
) return -1;
742 if (target_cpu
!= CPU_x86
) return -1;
743 /* make sure all the rest is digits */
744 for (p
= end
+ 1; *p
; p
++) if (!isdigit(*p
)) return -1;
746 return atoi( end
+ 1 );
750 /*******************************************************************
753 * Run a file through the assembler.
755 void assemble_file( const char *src_file
, const char *obj_file
)
757 struct strarray
*args
= get_as_command();
758 strarray_add( args
, "-o", obj_file
, src_file
, NULL
);
760 strarray_free( args
);
764 /*******************************************************************
767 * Create a new dll spec file descriptor
769 DLLSPEC
*alloc_dll_spec(void)
773 spec
= xmalloc( sizeof(*spec
) );
774 spec
->file_name
= NULL
;
775 spec
->dll_name
= NULL
;
776 spec
->init_func
= NULL
;
777 spec
->main_module
= NULL
;
778 spec
->type
= SPEC_WIN32
;
779 spec
->base
= MAX_ORDINALS
;
781 spec
->stack_size
= 0;
783 spec
->nb_entry_points
= 0;
784 spec
->alloc_entry_points
= 0;
786 spec
->nb_resources
= 0;
787 spec
->characteristics
= IMAGE_FILE_EXECUTABLE_IMAGE
;
788 if (get_ptr_size() > 4)
789 spec
->characteristics
|= IMAGE_FILE_LARGE_ADDRESS_AWARE
;
791 spec
->characteristics
|= IMAGE_FILE_32BIT_MACHINE
;
792 spec
->dll_characteristics
= IMAGE_DLLCHARACTERISTICS_NX_COMPAT
;
794 spec
->subsystem_major
= 4;
795 spec
->subsystem_minor
= 0;
796 spec
->entry_points
= NULL
;
798 spec
->ordinals
= NULL
;
799 spec
->resources
= NULL
;
804 /*******************************************************************
807 * Free dll spec file descriptor
809 void free_dll_spec( DLLSPEC
*spec
)
813 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
815 ORDDEF
*odp
= &spec
->entry_points
[i
];
817 free( odp
->export_name
);
818 free( odp
->link_name
);
820 free( spec
->file_name
);
821 free( spec
->dll_name
);
822 free( spec
->init_func
);
823 free( spec
->entry_points
);
825 free( spec
->ordinals
);
826 free( spec
->resources
);
831 /*******************************************************************
834 * Map a string to a valid C identifier.
836 const char *make_c_identifier( const char *str
)
838 static char buffer
[256];
841 for (p
= buffer
; *str
&& p
< buffer
+sizeof(buffer
)-1; p
++, str
++)
843 if (isalnum(*str
)) *p
= *str
;
851 /*******************************************************************
854 * Generate an internal name for a stub entry point.
856 const char *get_stub_name( const ORDDEF
*odp
, const DLLSPEC
*spec
)
861 if (odp
->name
|| odp
->export_name
)
864 buffer
= strmake( "__wine_stub_%s", odp
->name
? odp
->name
: odp
->export_name
);
865 /* make sure name is a legal C identifier */
866 for (p
= buffer
; *p
; p
++) if (!isalnum(*p
) && *p
!= '_') break;
867 if (!*p
) return buffer
;
870 buffer
= strmake( "__wine_stub_%s_%d", make_c_identifier(spec
->file_name
), odp
->ordinal
);
874 /* parse a cpu name and return the corresponding value */
875 enum target_cpu
get_cpu_from_name( const char *name
)
879 for (i
= 0; i
< sizeof(cpu_names
)/sizeof(cpu_names
[0]); i
++)
880 if (!strcmp( cpu_names
[i
].name
, name
)) return cpu_names
[i
].cpu
;
884 /*****************************************************************
885 * Function: get_alignment
888 * According to the info page for gas, the .align directive behaves
889 * differently on different systems. On some architectures, the
890 * argument of a .align directive is the number of bytes to pad to, so
891 * to align on an 8-byte boundary you'd say
893 * On other systems, the argument is "the number of low-order zero bits
894 * that the location counter must have after advancement." So to
895 * align on an 8-byte boundary you'd say
898 * The reason gas is written this way is that it's trying to mimick
899 * native assemblers for the various architectures it runs on. gas
900 * provides other directives that work consistently across
901 * architectures, but of course we want to work on all arches with or
902 * without gas. Hence this function.
906 * align -- the number of bytes to align to. Must be a power of 2.
908 unsigned int get_alignment(unsigned int align
)
912 assert( !(align
& (align
- 1)) );
918 if (target_platform
!= PLATFORM_APPLE
) return align
;
924 while ((1u << n
) != align
) n
++;
932 /* return the page size for the target CPU */
933 unsigned int get_page_size(void)
937 case CPU_x86
: return 4096;
938 case CPU_x86_64
: return 4096;
939 case CPU_POWERPC
: return 4096;
940 case CPU_ARM
: return 4096;
941 case CPU_ARM64
: return 4096;
948 /* return the size of a pointer on the target CPU */
949 unsigned int get_ptr_size(void)
966 /* return the total size in bytes of the arguments on the stack */
967 unsigned int get_args_size( const ORDDEF
*odp
)
971 for (i
= size
= 0; i
< odp
->u
.func
.nb_args
; i
++)
973 switch (odp
->u
.func
.args
[i
])
980 /* int128 is passed as pointer on x86_64 */
981 if (target_cpu
!= CPU_x86_64
)
988 size
+= get_ptr_size();
995 /* return the assembly name for a C symbol */
996 const char *asm_name( const char *sym
)
1000 switch (target_platform
)
1002 case PLATFORM_APPLE
:
1003 case PLATFORM_WINDOWS
:
1004 if (sym
[0] == '.' && sym
[1] == 'L') return sym
;
1006 buffer
= strmake( "_%s", sym
);
1013 /* return an assembly function declaration for a C function name */
1014 const char *func_declaration( const char *func
)
1016 static char *buffer
;
1018 switch (target_platform
)
1020 case PLATFORM_APPLE
:
1022 case PLATFORM_WINDOWS
:
1024 buffer
= strmake( ".def _%s; .scl 2; .type 32; .endef", func
);
1032 buffer
= strmake( ".type %s,%%function", func
);
1035 buffer
= strmake( ".type %s,@function", func
);
1043 /* output a size declaration for an assembly function */
1044 void output_function_size( const char *name
)
1046 switch (target_platform
)
1048 case PLATFORM_APPLE
:
1049 case PLATFORM_WINDOWS
:
1052 output( "\t.size %s, .-%s\n", name
, name
);
1057 /* output a .cfi directive */
1058 void output_cfi( const char *format
, ... )
1062 if (!unwind_tables
) return;
1063 va_start( valist
, format
);
1064 fputc( '\t', output_file
);
1065 vfprintf( output_file
, format
, valist
);
1066 fputc( '\n', output_file
);
1070 /* output the GNU note for non-exec stack */
1071 void output_gnu_stack_note(void)
1073 switch (target_platform
)
1075 case PLATFORM_WINDOWS
:
1076 case PLATFORM_APPLE
:
1083 output( "\t.section .note.GNU-stack,\"\",%%progbits\n" );
1086 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
1093 /* return a global symbol declaration for an assembly symbol */
1094 const char *asm_globl( const char *func
)
1096 static char *buffer
;
1099 switch (target_platform
)
1101 case PLATFORM_APPLE
:
1102 buffer
= strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func
, func
, func
);
1104 case PLATFORM_WINDOWS
:
1105 buffer
= strmake( "\t.globl _%s\n_%s:", func
, func
);
1108 buffer
= strmake( "\t.globl %s\n\t.hidden %s\n%s:", func
, func
, func
);
1114 const char *get_asm_ptr_keyword(void)
1116 switch(get_ptr_size())
1118 case 4: return ".long";
1119 case 8: return ".quad";
1125 const char *get_asm_string_keyword(void)
1127 switch (target_platform
)
1129 case PLATFORM_APPLE
:
1136 const char *get_asm_rodata_section(void)
1138 switch (target_platform
)
1140 case PLATFORM_APPLE
: return ".const";
1141 default: return ".section .rodata";
1145 const char *get_asm_string_section(void)
1147 switch (target_platform
)
1149 case PLATFORM_APPLE
: return ".cstring";
1150 default: return ".section .rodata";