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 #if defined(_WIN32) && !defined(__CYGWIN__)
43 # define PATH_SEPARATOR ';'
45 # define PATH_SEPARATOR ':'
48 static const char **tmp_files
;
49 static unsigned int nb_tmp_files
;
50 static unsigned int max_tmp_files
;
63 { "amd64", CPU_x86_64
},
64 { "x86_64", CPU_x86_64
},
65 { "powerpc", CPU_POWERPC
},
67 { "arm64", CPU_ARM64
},
68 { "aarch64", CPU_ARM64
},
71 /* atexit handler to clean tmp files */
72 void cleanup_tmp_files(void)
75 for (i
= 0; i
< nb_tmp_files
; i
++) if (tmp_files
[i
]) unlink( tmp_files
[i
] );
79 void *xmalloc (size_t size
)
83 res
= malloc (size
? size
: 1);
86 fprintf (stderr
, "Virtual memory exhausted.\n");
92 void *xrealloc (void *ptr
, size_t size
)
94 void *res
= realloc (ptr
, size
);
95 if (size
&& res
== NULL
)
97 fprintf (stderr
, "Virtual memory exhausted.\n");
103 char *xstrdup( const char *str
)
105 char *res
= strdup( str
);
108 fprintf (stderr
, "Virtual memory exhausted.\n");
114 char *strupper(char *s
)
117 for (p
= s
; *p
; p
++) *p
= toupper(*p
);
121 int strendswith(const char* str
, const char* end
)
125 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
128 char *strmake( const char* fmt
, ... )
136 char *p
= xmalloc( size
);
138 n
= vsnprintf( p
, size
, fmt
, ap
);
140 if (n
== -1) size
*= 2;
141 else if ((size_t)n
>= size
) size
= n
+ 1;
147 static struct strarray
*strarray_init( const char *str
)
149 struct strarray
*array
= xmalloc( sizeof(*array
) );
152 array
->str
= xmalloc( array
->max
* sizeof(*array
->str
) );
153 if (str
) array
->str
[array
->count
++] = str
;
157 static struct strarray
*strarray_copy( const struct strarray
*src
)
159 struct strarray
*array
= xmalloc( sizeof(*array
) );
160 array
->count
= src
->count
;
161 array
->max
= src
->max
;
162 array
->str
= xmalloc( array
->max
* sizeof(*array
->str
) );
163 memcpy( array
->str
, src
->str
, array
->count
* sizeof(*array
->str
) );
167 static void strarray_add_one( struct strarray
*array
, const char *str
)
169 if (array
->count
== array
->max
)
172 array
->str
= xrealloc( array
->str
, array
->max
* sizeof(*array
->str
) );
174 array
->str
[array
->count
++] = str
;
177 void strarray_add( struct strarray
*array
, ... )
182 va_start( valist
, array
);
183 while ((str
= va_arg( valist
, const char *))) strarray_add_one( array
, str
);
187 void strarray_addv( struct strarray
*array
, char * const *argv
)
189 while (*argv
) strarray_add_one( array
, *argv
++ );
192 struct strarray
*strarray_fromstring( const char *str
, const char *delim
)
195 struct strarray
*array
= strarray_init( NULL
);
196 char *buf
= strdup( str
);
198 for (tok
= strtok( buf
, delim
); tok
; tok
= strtok( NULL
, delim
))
199 strarray_add_one( array
, strdup( tok
));
205 void strarray_free( struct strarray
*array
)
211 void fatal_error( const char *msg
, ... )
214 va_start( valist
, msg
);
217 fprintf( stderr
, "%s:", input_file_name
);
219 fprintf( stderr
, "%d:", current_line
);
220 fputc( ' ', stderr
);
222 else fprintf( stderr
, "winebuild: " );
223 vfprintf( stderr
, msg
, valist
);
228 void fatal_perror( const char *msg
, ... )
231 va_start( valist
, msg
);
234 fprintf( stderr
, "%s:", input_file_name
);
236 fprintf( stderr
, "%d:", current_line
);
237 fputc( ' ', stderr
);
239 vfprintf( stderr
, msg
, valist
);
245 void error( const char *msg
, ... )
248 va_start( valist
, msg
);
251 fprintf( stderr
, "%s:", input_file_name
);
253 fprintf( stderr
, "%d:", current_line
);
254 fputc( ' ', stderr
);
256 vfprintf( stderr
, msg
, valist
);
261 void warning( const char *msg
, ... )
265 if (!display_warnings
) return;
266 va_start( valist
, msg
);
269 fprintf( stderr
, "%s:", input_file_name
);
271 fprintf( stderr
, "%d:", current_line
);
272 fputc( ' ', stderr
);
274 fprintf( stderr
, "warning: " );
275 vfprintf( stderr
, msg
, valist
);
279 int output( const char *format
, ... )
284 va_start( valist
, format
);
285 ret
= vfprintf( output_file
, format
, valist
);
287 if (ret
< 0) fatal_perror( "Output error" );
291 void spawn( struct strarray
*args
)
296 strarray_add_one( args
, NULL
);
298 for (i
= 0; args
->str
[i
]; i
++)
299 fprintf( stderr
, "%s%c", args
->str
[i
], args
->str
[i
+1] ? ' ' : '\n' );
301 if ((status
= _spawnvp( _P_WAIT
, args
->str
[0], args
->str
)))
303 if (status
> 0) fatal_error( "%s failed with status %u\n", args
->str
[0], status
);
304 else fatal_perror( "winebuild" );
309 /* find a build tool in the path, trying the various names */
310 struct strarray
*find_tool( const char *name
, const char * const *names
)
313 static unsigned int count
, maxlen
;
316 const char *alt_names
[2];
324 /* split the path in directories */
326 if (!getenv( "PATH" )) fatal_error( "PATH not set, cannot find required tools\n" );
327 path
= xstrdup( getenv( "PATH" ));
328 for (p
= path
, count
= 2; *p
; p
++) if (*p
== PATH_SEPARATOR
) count
++;
329 dirs
= xmalloc( count
* sizeof(*dirs
) );
331 dirs
[count
++] = p
= path
;
334 while (*p
&& *p
!= PATH_SEPARATOR
) p
++;
339 for (i
= 0; i
< count
; i
++) maxlen
= max( maxlen
, strlen(dirs
[i
])+2 );
351 len
= strlen(*names
) + sizeof(EXEEXT
) + 1;
353 len
+= strlen(target_alias
) + 1;
354 file
= xmalloc( maxlen
+ len
);
356 for (i
= 0; i
< count
; i
++)
358 strcpy( file
, dirs
[i
] );
359 p
= file
+ strlen(file
);
360 if (p
== file
) *p
++ = '.';
361 if (p
[-1] != '/') *p
++ = '/';
364 strcpy( p
, target_alias
);
371 if (!stat( file
, &st
) && S_ISREG(st
.st_mode
) && (st
.st_mode
& 0111))
372 return strarray_init( file
);
377 fatal_error( "cannot find the '%s' tool\n", name
);
380 struct strarray
*get_as_command(void)
382 struct strarray
*args
;
386 args
= strarray_copy( cc_command
);
387 strarray_add( args
, "-xassembler", "-c", NULL
);
388 if (force_pointer_size
)
389 strarray_add_one( args
, (force_pointer_size
== 8) ? "-m64" : "-m32" );
390 if (cpu_option
) strarray_add_one( args
, strmake("-mcpu=%s", cpu_option
) );
396 static const char * const commands
[] = { "gas", "as", NULL
};
397 as_command
= find_tool( "as", commands
);
400 args
= strarray_copy( as_command
);
402 if (force_pointer_size
)
404 switch (target_platform
)
407 strarray_add( args
, "-arch", (force_pointer_size
== 8) ? "x86_64" : "i386", NULL
);
413 strarray_add_one( args
, (force_pointer_size
== 8) ? "-a64" : "-a32" );
416 strarray_add_one( args
, (force_pointer_size
== 8) ? "--64" : "--32" );
423 if (cpu_option
) strarray_add_one( args
, strmake("-mcpu=%s", cpu_option
) );
427 struct strarray
*get_ld_command(void)
429 struct strarray
*args
;
433 static const char * const commands
[] = { "ld", "gld", NULL
};
434 ld_command
= find_tool( "ld", commands
);
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
);
472 if (nm_command
->count
> 1)
473 fatal_error( "multiple arguments in nm command not supported yet\n" );
474 return nm_command
->str
[0];
477 /* get a name for a temp file, automatically cleaned up on exit */
478 char *get_temp_file_name( const char *prefix
, const char *suffix
)
481 const char *ext
, *basename
;
484 if (!prefix
|| !prefix
[0]) prefix
= "winebuild";
485 if (!suffix
) suffix
= "";
486 if ((basename
= strrchr( prefix
, '/' ))) basename
++;
487 else basename
= prefix
;
488 if (!(ext
= strchr( basename
, '.' ))) ext
= prefix
+ strlen(prefix
);
489 name
= xmalloc( sizeof("/tmp/") + (ext
- prefix
) + sizeof(".XXXXXX") + strlen(suffix
) );
490 memcpy( name
, prefix
, ext
- prefix
);
491 strcpy( name
+ (ext
- prefix
), ".XXXXXX" );
492 strcat( name
, suffix
);
494 if ((fd
= mkstemps( name
, strlen(suffix
) )) == -1)
496 strcpy( name
, "/tmp/" );
497 memcpy( name
+ 5, basename
, ext
- basename
);
498 strcpy( name
+ 5 + (ext
- basename
), ".XXXXXX" );
499 strcat( name
, suffix
);
500 if ((fd
= mkstemps( name
, strlen(suffix
) )) == -1)
501 fatal_error( "could not generate a temp file\n" );
505 if (nb_tmp_files
>= max_tmp_files
)
507 max_tmp_files
= max( 2 * max_tmp_files
, 8 );
508 tmp_files
= xrealloc( tmp_files
, max_tmp_files
* sizeof(tmp_files
[0]) );
510 tmp_files
[nb_tmp_files
++] = name
;
514 /*******************************************************************
517 * Function for reading from/writing to a memory buffer.
520 int byte_swapped
= 0;
521 const char *input_buffer_filename
;
522 const unsigned char *input_buffer
;
523 size_t input_buffer_pos
;
524 size_t input_buffer_size
;
525 unsigned char *output_buffer
;
526 size_t output_buffer_pos
;
527 size_t output_buffer_size
;
529 static void check_output_buffer_space( size_t size
)
531 if (output_buffer_pos
+ size
>= output_buffer_size
)
533 output_buffer_size
= max( output_buffer_size
* 2, output_buffer_pos
+ size
);
534 output_buffer
= xrealloc( output_buffer
, output_buffer_size
);
538 void init_input_buffer( const char *file
)
543 if ((fd
= open( file
, O_RDONLY
| O_BINARY
)) == -1) fatal_perror( "Cannot open %s", file
);
544 if ((fstat( fd
, &st
) == -1)) fatal_perror( "Cannot stat %s", file
);
545 if (!st
.st_size
) fatal_error( "%s is an empty file\n", file
);
547 if ((input_buffer
= mmap( NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0 )) == (void*)-1)
550 unsigned char *buffer
= xmalloc( st
.st_size
);
551 if (read( fd
, buffer
, st
.st_size
) != st
.st_size
) fatal_error( "Cannot read %s\n", file
);
552 input_buffer
= buffer
;
555 input_buffer_filename
= xstrdup( file
);
556 input_buffer_size
= st
.st_size
;
557 input_buffer_pos
= 0;
561 void init_output_buffer(void)
563 output_buffer_size
= 1024;
564 output_buffer_pos
= 0;
565 output_buffer
= xmalloc( output_buffer_size
);
568 void flush_output_buffer(void)
570 if (fwrite( output_buffer
, 1, output_buffer_pos
, output_file
) != output_buffer_pos
)
571 fatal_error( "Error writing to %s\n", output_file_name
);
572 free( output_buffer
);
575 unsigned char get_byte(void)
577 if (input_buffer_pos
>= input_buffer_size
)
578 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
579 return input_buffer
[input_buffer_pos
++];
582 unsigned short get_word(void)
586 if (input_buffer_pos
+ sizeof(ret
) > input_buffer_size
)
587 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
588 memcpy( &ret
, input_buffer
+ input_buffer_pos
, sizeof(ret
) );
589 if (byte_swapped
) ret
= (ret
<< 8) | (ret
>> 8);
590 input_buffer_pos
+= sizeof(ret
);
594 unsigned int get_dword(void)
598 if (input_buffer_pos
+ sizeof(ret
) > input_buffer_size
)
599 fatal_error( "%s is a truncated file\n", input_buffer_filename
);
600 memcpy( &ret
, input_buffer
+ input_buffer_pos
, sizeof(ret
) );
602 ret
= ((ret
<< 24) | ((ret
<< 8) & 0x00ff0000) | ((ret
>> 8) & 0x0000ff00) | (ret
>> 24));
603 input_buffer_pos
+= sizeof(ret
);
607 void put_data( const void *data
, size_t size
)
609 check_output_buffer_space( size
);
610 memcpy( output_buffer
+ output_buffer_pos
, data
, size
);
611 output_buffer_pos
+= size
;
614 void put_byte( unsigned char val
)
616 check_output_buffer_space( 1 );
617 output_buffer
[output_buffer_pos
++] = val
;
620 void put_word( unsigned short val
)
622 if (byte_swapped
) val
= (val
<< 8) | (val
>> 8);
623 put_data( &val
, sizeof(val
) );
626 void put_dword( unsigned int val
)
629 val
= ((val
<< 24) | ((val
<< 8) & 0x00ff0000) | ((val
>> 8) & 0x0000ff00) | (val
>> 24));
630 put_data( &val
, sizeof(val
) );
633 void put_qword( unsigned int val
)
647 /* pointer-sized word */
648 void put_pword( unsigned int val
)
650 if (get_ptr_size() == 8) put_qword( val
);
651 else put_dword( val
);
654 void align_output( unsigned int align
)
656 size_t size
= align
- (output_buffer_pos
% align
);
658 if (size
== align
) return;
659 check_output_buffer_space( size
);
660 memset( output_buffer
+ output_buffer_pos
, 0, size
);
661 output_buffer_pos
+= size
;
664 /* output a standard header for generated files */
665 void output_standard_file_header(void)
668 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name
);
670 output( "/* File generated automatically; do not edit! */\n" );
671 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
674 /* dump a byte stream into the assembly code */
675 void dump_bytes( const void *buffer
, unsigned int size
)
678 const unsigned char *ptr
= buffer
;
681 output( "\t.byte " );
682 for (i
= 0; i
< size
- 1; i
++, ptr
++)
684 if ((i
% 16) == 15) output( "0x%02x\n\t.byte ", *ptr
);
685 else output( "0x%02x,", *ptr
);
687 output( "0x%02x\n", *ptr
);
691 /*******************************************************************
694 * Open a file in the given srcdir and set the input_file_name global variable.
696 FILE *open_input_file( const char *srcdir
, const char *name
)
699 FILE *file
= fopen( name
, "r" );
703 fullname
= strmake( "%s/%s", srcdir
, name
);
704 file
= fopen( fullname
, "r" );
706 else fullname
= xstrdup( name
);
708 if (!file
) fatal_error( "Cannot open file '%s'\n", fullname
);
709 input_file_name
= fullname
;
715 /*******************************************************************
718 * Close the current input file (must have been opened with open_input_file).
720 void close_input_file( FILE *file
)
723 free( input_file_name
);
724 input_file_name
= NULL
;
729 /*******************************************************************
730 * remove_stdcall_decoration
732 * Remove a possible @xx suffix from a function name.
733 * Return the numerical value of the suffix, or -1 if none.
735 int remove_stdcall_decoration( char *name
)
737 char *p
, *end
= strrchr( name
, '@' );
738 if (!end
|| !end
[1] || end
== name
) return -1;
739 if (target_cpu
!= CPU_x86
) return -1;
740 /* make sure all the rest is digits */
741 for (p
= end
+ 1; *p
; p
++) if (!isdigit(*p
)) return -1;
743 return atoi( end
+ 1 );
747 /*******************************************************************
750 * Run a file through the assembler.
752 void assemble_file( const char *src_file
, const char *obj_file
)
754 struct strarray
*args
= get_as_command();
755 strarray_add( args
, "-o", obj_file
, src_file
, NULL
);
757 strarray_free( args
);
761 /*******************************************************************
764 * Create a new dll spec file descriptor
766 DLLSPEC
*alloc_dll_spec(void)
770 spec
= xmalloc( sizeof(*spec
) );
771 spec
->file_name
= NULL
;
772 spec
->dll_name
= NULL
;
773 spec
->init_func
= NULL
;
774 spec
->main_module
= NULL
;
775 spec
->type
= SPEC_WIN32
;
776 spec
->base
= MAX_ORDINALS
;
778 spec
->stack_size
= 0;
780 spec
->nb_entry_points
= 0;
781 spec
->alloc_entry_points
= 0;
783 spec
->nb_resources
= 0;
784 spec
->characteristics
= IMAGE_FILE_EXECUTABLE_IMAGE
;
785 if (get_ptr_size() > 4)
786 spec
->characteristics
|= IMAGE_FILE_LARGE_ADDRESS_AWARE
;
788 spec
->characteristics
|= IMAGE_FILE_32BIT_MACHINE
;
789 spec
->dll_characteristics
= IMAGE_DLLCHARACTERISTICS_NX_COMPAT
;
791 spec
->subsystem_major
= 4;
792 spec
->subsystem_minor
= 0;
793 spec
->entry_points
= NULL
;
795 spec
->ordinals
= NULL
;
796 spec
->resources
= NULL
;
801 /*******************************************************************
804 * Free dll spec file descriptor
806 void free_dll_spec( DLLSPEC
*spec
)
810 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
812 ORDDEF
*odp
= &spec
->entry_points
[i
];
814 free( odp
->export_name
);
815 free( odp
->link_name
);
817 free( spec
->file_name
);
818 free( spec
->dll_name
);
819 free( spec
->init_func
);
820 free( spec
->entry_points
);
822 free( spec
->ordinals
);
823 free( spec
->resources
);
828 /*******************************************************************
831 * Map a string to a valid C identifier.
833 const char *make_c_identifier( const char *str
)
835 static char buffer
[256];
838 for (p
= buffer
; *str
&& p
< buffer
+sizeof(buffer
)-1; p
++, str
++)
840 if (isalnum(*str
)) *p
= *str
;
848 /*******************************************************************
851 * Generate an internal name for a stub entry point.
853 const char *get_stub_name( const ORDDEF
*odp
, const DLLSPEC
*spec
)
858 if (odp
->name
|| odp
->export_name
)
861 buffer
= strmake( "__wine_stub_%s", odp
->name
? odp
->name
: odp
->export_name
);
862 /* make sure name is a legal C identifier */
863 for (p
= buffer
; *p
; p
++) if (!isalnum(*p
) && *p
!= '_') break;
864 if (!*p
) return buffer
;
867 buffer
= strmake( "__wine_stub_%s_%d", make_c_identifier(spec
->file_name
), odp
->ordinal
);
871 /* parse a cpu name and return the corresponding value */
872 enum target_cpu
get_cpu_from_name( const char *name
)
876 for (i
= 0; i
< sizeof(cpu_names
)/sizeof(cpu_names
[0]); i
++)
877 if (!strcmp( cpu_names
[i
].name
, name
)) return cpu_names
[i
].cpu
;
881 /*****************************************************************
882 * Function: get_alignment
885 * According to the info page for gas, the .align directive behaves
886 * differently on different systems. On some architectures, the
887 * argument of a .align directive is the number of bytes to pad to, so
888 * to align on an 8-byte boundary you'd say
890 * On other systems, the argument is "the number of low-order zero bits
891 * that the location counter must have after advancement." So to
892 * align on an 8-byte boundary you'd say
895 * The reason gas is written this way is that it's trying to mimick
896 * native assemblers for the various architectures it runs on. gas
897 * provides other directives that work consistently across
898 * architectures, but of course we want to work on all arches with or
899 * without gas. Hence this function.
903 * align -- the number of bytes to align to. Must be a power of 2.
905 unsigned int get_alignment(unsigned int align
)
909 assert( !(align
& (align
- 1)) );
915 if (target_platform
!= PLATFORM_APPLE
) return align
;
921 while ((1u << n
) != align
) n
++;
929 /* return the page size for the target CPU */
930 unsigned int get_page_size(void)
934 case CPU_x86
: return 4096;
935 case CPU_x86_64
: return 4096;
936 case CPU_POWERPC
: return 4096;
937 case CPU_ARM
: return 4096;
938 case CPU_ARM64
: return 4096;
945 /* return the size of a pointer on the target CPU */
946 unsigned int get_ptr_size(void)
963 /* return the total size in bytes of the arguments on the stack */
964 unsigned int get_args_size( const ORDDEF
*odp
)
968 for (i
= size
= 0; i
< odp
->u
.func
.nb_args
; i
++)
970 switch (odp
->u
.func
.args
[i
])
977 /* int128 is passed as pointer on x86_64 */
978 if (target_cpu
!= CPU_x86_64
)
985 size
+= get_ptr_size();
992 /* return the assembly name for a C symbol */
993 const char *asm_name( const char *sym
)
997 switch (target_platform
)
1000 case PLATFORM_WINDOWS
:
1001 if (sym
[0] == '.' && sym
[1] == 'L') return sym
;
1003 buffer
= strmake( "_%s", sym
);
1010 /* return an assembly function declaration for a C function name */
1011 const char *func_declaration( const char *func
)
1013 static char *buffer
;
1015 switch (target_platform
)
1017 case PLATFORM_APPLE
:
1019 case PLATFORM_WINDOWS
:
1021 buffer
= strmake( ".def _%s; .scl 2; .type 32; .endef", func
);
1029 buffer
= strmake( ".type %s,%%function", func
);
1032 buffer
= strmake( ".type %s,@function", func
);
1040 /* output a size declaration for an assembly function */
1041 void output_function_size( const char *name
)
1043 switch (target_platform
)
1045 case PLATFORM_APPLE
:
1046 case PLATFORM_WINDOWS
:
1049 output( "\t.size %s, .-%s\n", name
, name
);
1054 /* output a .cfi directive */
1055 void output_cfi( const char *format
, ... )
1059 if (!unwind_tables
) return;
1060 va_start( valist
, format
);
1061 fputc( '\t', output_file
);
1062 vfprintf( output_file
, format
, valist
);
1063 fputc( '\n', output_file
);
1067 /* output the GNU note for non-exec stack */
1068 void output_gnu_stack_note(void)
1070 switch (target_platform
)
1072 case PLATFORM_WINDOWS
:
1073 case PLATFORM_APPLE
:
1080 output( "\t.section .note.GNU-stack,\"\",%%progbits\n" );
1083 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
1090 /* return a global symbol declaration for an assembly symbol */
1091 const char *asm_globl( const char *func
)
1093 static char *buffer
;
1096 switch (target_platform
)
1098 case PLATFORM_APPLE
:
1099 buffer
= strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func
, func
, func
);
1101 case PLATFORM_WINDOWS
:
1102 buffer
= strmake( "\t.globl _%s\n_%s:", func
, func
);
1105 buffer
= strmake( "\t.globl %s\n\t.hidden %s\n%s:", func
, func
, func
);
1111 const char *get_asm_ptr_keyword(void)
1113 switch(get_ptr_size())
1115 case 4: return ".long";
1116 case 8: return ".quad";
1122 const char *get_asm_string_keyword(void)
1124 switch (target_platform
)
1126 case PLATFORM_APPLE
:
1133 const char *get_asm_rodata_section(void)
1135 switch (target_platform
)
1137 case PLATFORM_APPLE
: return ".const";
1138 default: return ".section .rodata";
1142 const char *get_asm_string_section(void)
1144 switch (target_platform
)
1146 case PLATFORM_APPLE
: return ".cstring";
1147 default: return ".section .rodata";