winebuild: Remove some no longer used support for ELF ARM platforms.
[wine.git] / tools / winebuild / utils.c
blob62f05e535b6f14c0fb992cd78c45246e696f116f
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"
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "build.h"
32 const char *temp_dir = NULL;
33 struct strarray temp_files = { 0 };
34 static const char *output_file_source_name;
36 char *strupper(char *s)
38 char *p;
39 for (p = s; *p; p++) *p = toupper(*p);
40 return s;
43 void fatal_error( const char *msg, ... )
45 va_list valist;
46 va_start( valist, msg );
47 if (input_file_name)
49 fprintf( stderr, "%s:", input_file_name );
50 if (current_line)
51 fprintf( stderr, "%d:", current_line );
52 fputc( ' ', stderr );
54 else fprintf( stderr, "winebuild: " );
55 vfprintf( stderr, msg, valist );
56 va_end( valist );
57 exit(1);
60 void fatal_perror( const char *msg, ... )
62 va_list valist;
63 va_start( valist, msg );
64 if (input_file_name)
66 fprintf( stderr, "%s:", input_file_name );
67 if (current_line)
68 fprintf( stderr, "%d:", current_line );
69 fputc( ' ', stderr );
71 vfprintf( stderr, msg, valist );
72 perror( " " );
73 va_end( valist );
74 exit(1);
77 void error( const char *msg, ... )
79 va_list valist;
80 va_start( valist, msg );
81 if (input_file_name)
83 fprintf( stderr, "%s:", input_file_name );
84 if (current_line)
85 fprintf( stderr, "%d:", current_line );
86 fputc( ' ', stderr );
88 vfprintf( stderr, msg, valist );
89 va_end( valist );
90 nb_errors++;
93 void warning( const char *msg, ... )
95 va_list valist;
97 if (!display_warnings) return;
98 va_start( valist, msg );
99 if (input_file_name)
101 fprintf( stderr, "%s:", input_file_name );
102 if (current_line)
103 fprintf( stderr, "%d:", current_line );
104 fputc( ' ', stderr );
106 fprintf( stderr, "warning: " );
107 vfprintf( stderr, msg, valist );
108 va_end( valist );
111 int output( const char *format, ... )
113 int ret;
114 va_list valist;
116 va_start( valist, format );
117 ret = vfprintf( output_file, format, valist );
118 va_end( valist );
119 if (ret < 0) fatal_perror( "Output error" );
120 return ret;
123 static struct strarray get_tools_path(void)
125 static int done;
126 static struct strarray dirs;
128 if (!done)
130 strarray_addall( &dirs, tools_path );
131 strarray_addall( &dirs, strarray_frompath( getenv( "PATH" )));
132 done = 1;
134 return dirs;
137 /* find a binary in the path */
138 static const char *find_binary( const char *prefix, const char *name )
140 struct strarray dirs = get_tools_path();
141 unsigned int i, maxlen = 0;
142 struct stat st;
143 char *p, *file;
145 if (strchr( name, '/' )) return name;
146 if (!prefix) prefix = "";
147 for (i = 0; i < dirs.count; i++) maxlen = max( maxlen, strlen(dirs.str[i]) + 2 );
148 file = xmalloc( maxlen + strlen(prefix) + strlen(name) + sizeof(EXEEXT) + 1 );
150 for (i = 0; i < dirs.count; i++)
152 strcpy( file, dirs.str[i] );
153 p = file + strlen(file);
154 if (p == file) *p++ = '.';
155 if (p[-1] != '/') *p++ = '/';
156 if (*prefix)
158 strcpy( p, prefix );
159 p += strlen(p);
160 *p++ = '-';
162 strcpy( p, name );
163 strcat( p, EXEEXT );
164 if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111)) return file;
166 free( file );
167 return NULL;
170 void spawn( struct strarray args )
172 int status;
173 const char *argv0 = find_binary( NULL, args.str[0] );
175 if (argv0) args.str[0] = argv0;
176 if (verbose) strarray_trace( args );
178 if ((status = strarray_spawn( args )))
180 if (status > 0) fatal_error( "%s failed with status %u\n", args.str[0], status );
181 else fatal_perror( "winebuild" );
182 exit( 1 );
186 static const char *find_clang_tool( struct strarray clang, const char *tool )
188 const char *out = make_temp_file( "print_tool", ".out" );
189 struct strarray args = empty_strarray;
190 int sout = -1;
191 char *path, *p;
192 struct stat st;
193 size_t cnt;
195 strarray_addall( &args, clang );
196 if (!args.count) strarray_add( &args, "clang" );
197 strarray_add( &args, strmake( "-print-prog-name=%s", tool ));
198 if (verbose) strarray_add( &args, "-v" );
200 sout = dup( fileno(stdout) );
201 freopen( out, "w", stdout );
202 spawn( args );
203 if (sout >= 0)
205 dup2( sout, fileno(stdout) );
206 close( sout );
209 if (stat(out, &st) || !st.st_size) return NULL;
211 path = xmalloc(st.st_size + 1);
212 sout = open(out, O_RDONLY);
213 if (sout == -1) return NULL;
214 cnt = read(sout, path, st.st_size);
215 close(sout);
216 path[cnt] = 0;
217 if ((p = strchr(path, '\n'))) *p = 0;
218 /* clang returns passed command instead of full path if the tool could not be found */
219 if (!strcmp(path, tool))
221 free( path );
222 return NULL;
224 return path;
227 /* find a build tool in the path, trying the various names */
228 struct strarray find_tool( const char *name, const char * const *names )
230 struct strarray ret = empty_strarray;
231 const char *file;
232 const char *alt_names[2];
234 if (!names)
236 alt_names[0] = name;
237 alt_names[1] = NULL;
238 names = alt_names;
241 while (*names)
243 if ((file = find_binary( target_alias, *names ))) break;
244 names++;
247 if (!file && cc_command.count) file = find_clang_tool( cc_command, name );
248 if (!file) file = find_binary( "llvm", name );
249 if (!file) file = find_clang_tool( empty_strarray, strmake( "llvm-%s", name ));
250 if (!file) file = find_clang_tool( empty_strarray, name );
252 if (!file) fatal_error( "cannot find the '%s' tool\n", name );
254 strarray_add( &ret, file );
255 return ret;
258 /* find a link tool in the path */
259 struct strarray find_link_tool(void)
261 struct strarray ret = empty_strarray;
262 const char *file = NULL;
264 if (cc_command.count) file = find_clang_tool( cc_command, "lld-link" );
265 if (!file) file = find_binary( NULL, "lld-link" );
266 if (!file) file = find_clang_tool( empty_strarray, "lld-link" );
268 if (!file) fatal_error( "cannot find the 'lld-link' tool\n" );
269 strarray_add( &ret, file );
270 return ret;
273 struct strarray get_as_command(void)
275 struct strarray args = empty_strarray;
276 const char *file;
277 unsigned int i;
278 int using_cc = 0;
280 if (cc_command.count)
282 strarray_addall( &args, cc_command );
283 using_cc = 1;
285 else if (as_command.count)
287 strarray_addall( &args, as_command );
289 else if ((file = find_binary( target_alias, "as" )) || (file = find_binary( target_alias, "gas ")))
291 strarray_add( &args, file );
293 else if ((file = find_binary( NULL, "clang" )))
295 strarray_add( &args, file );
296 if (target_alias)
298 strarray_add( &args, "-target" );
299 strarray_add( &args, target_alias );
301 using_cc = 1;
304 if (using_cc)
306 strarray_add( &args, "-xassembler" );
307 strarray_add( &args, "-c" );
308 if (force_pointer_size)
309 strarray_add( &args, (force_pointer_size == 8) ? "-m64" : "-m32" );
310 if (cpu_option) strarray_add( &args, strmake("-mcpu=%s", cpu_option) );
311 if (fpu_option) strarray_add( &args, strmake("-mfpu=%s", fpu_option) );
312 if (arch_option) strarray_add( &args, strmake("-march=%s", arch_option) );
313 for (i = 0; i < tools_path.count; i++)
314 strarray_add( &args, strmake("-B%s", tools_path.str[i] ));
315 return args;
318 if (force_pointer_size)
320 switch (target.platform)
322 case PLATFORM_APPLE:
323 strarray_add( &args, "-arch" );
324 strarray_add( &args, (force_pointer_size == 8) ? "x86_64" : "i386" );
325 break;
326 default:
327 strarray_add( &args, (force_pointer_size == 8) ? "--64" : "--32" );
328 break;
332 if (cpu_option) strarray_add( &args, strmake("-mcpu=%s", cpu_option) );
333 if (fpu_option) strarray_add( &args, strmake("-mfpu=%s", fpu_option) );
334 return args;
337 struct strarray get_ld_command(void)
339 struct strarray args = empty_strarray;
341 if (!ld_command.count)
343 static const char * const commands[] = { "ld", "gld", NULL };
344 ld_command = find_tool( "ld", commands );
347 strarray_addall( &args, ld_command );
349 if (force_pointer_size)
351 switch (target.platform)
353 case PLATFORM_APPLE:
354 strarray_add( &args, "-arch" );
355 strarray_add( &args, (force_pointer_size == 8) ? "x86_64" : "i386" );
356 break;
357 case PLATFORM_FREEBSD:
358 strarray_add( &args, "-m" );
359 strarray_add( &args, (force_pointer_size == 8) ? "elf_x86_64_fbsd" : "elf_i386_fbsd" );
360 break;
361 case PLATFORM_MINGW:
362 case PLATFORM_WINDOWS:
363 strarray_add( &args, "-m" );
364 strarray_add( &args, (force_pointer_size == 8) ? "i386pep" : "i386pe" );
365 break;
366 default:
367 strarray_add( &args, "-m" );
368 strarray_add( &args, (force_pointer_size == 8) ? "elf_x86_64" : "elf_i386" );
369 break;
373 if (target.cpu == CPU_ARM && !is_pe())
374 strarray_add( &args, "--no-wchar-size-warning" );
376 return args;
379 const char *get_nm_command(void)
381 if (!nm_command.count)
383 static const char * const commands[] = { "nm", "gnm", NULL };
384 nm_command = find_tool( "nm", commands );
386 if (nm_command.count > 1)
387 fatal_error( "multiple arguments in nm command not supported yet\n" );
388 return nm_command.str[0];
392 /*******************************************************************
393 * buffer management
395 * Function for reading from/writing to a memory buffer.
398 int byte_swapped = 0;
399 const char *input_buffer_filename;
400 const unsigned char *input_buffer;
401 size_t input_buffer_pos;
402 size_t input_buffer_size;
403 unsigned char *output_buffer;
404 size_t output_buffer_pos;
405 size_t output_buffer_size;
407 void init_input_buffer( const char *file )
409 if (!(input_buffer = read_file( file, &input_buffer_size ))) fatal_perror( "Cannot read %s", file );
410 if (!input_buffer_size) fatal_error( "%s is an empty file\n", file );
411 input_buffer_filename = xstrdup( file );
412 input_buffer_pos = 0;
413 byte_swapped = 0;
416 unsigned char get_byte(void)
418 if (input_buffer_pos >= input_buffer_size)
419 fatal_error( "%s is a truncated file\n", input_buffer_filename );
420 return input_buffer[input_buffer_pos++];
423 unsigned short get_word(void)
425 unsigned short ret;
427 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
428 fatal_error( "%s is a truncated file\n", input_buffer_filename );
429 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
430 if (byte_swapped) ret = (ret << 8) | (ret >> 8);
431 input_buffer_pos += sizeof(ret);
432 return ret;
435 unsigned int get_dword(void)
437 unsigned int ret;
439 if (input_buffer_pos + sizeof(ret) > input_buffer_size)
440 fatal_error( "%s is a truncated file\n", input_buffer_filename );
441 memcpy( &ret, input_buffer + input_buffer_pos, sizeof(ret) );
442 if (byte_swapped)
443 ret = ((ret << 24) | ((ret << 8) & 0x00ff0000) | ((ret >> 8) & 0x0000ff00) | (ret >> 24));
444 input_buffer_pos += sizeof(ret);
445 return ret;
448 /* pointer-sized word */
449 void put_pword( unsigned int val )
451 if (get_ptr_size() == 8) put_qword( val );
452 else put_dword( val );
455 /* output a standard header for generated files */
456 void output_standard_file_header(void)
458 if (spec_file_name)
459 output( "/* File generated automatically from %s; do not edit! */\n", spec_file_name );
460 else
461 output( "/* File generated automatically; do not edit! */\n" );
462 output( "/* This file can be copied, modified and distributed without restriction. */\n\n" );
463 if (safe_seh)
465 output( "\t.def @feat.00\n\t.scl 3\n\t.type 0\n\t.endef\n" );
466 output( "\t.globl @feat.00\n" );
467 output( ".set @feat.00, 1\n" );
471 /* dump a byte stream into the assembly code */
472 void dump_bytes( const void *buffer, unsigned int size )
474 unsigned int i;
475 const unsigned char *ptr = buffer;
477 if (!size) return;
478 output( "\t.byte " );
479 for (i = 0; i < size - 1; i++, ptr++)
481 if ((i % 16) == 15) output( "0x%02x\n\t.byte ", *ptr );
482 else output( "0x%02x,", *ptr );
484 output( "0x%02x\n", *ptr );
488 /*******************************************************************
489 * open_input_file
491 * Open a file in the given srcdir and set the input_file_name global variable.
493 FILE *open_input_file( const char *srcdir, const char *name )
495 char *fullname;
496 FILE *file = fopen( name, "r" );
498 if (!file && srcdir)
500 fullname = strmake( "%s/%s", srcdir, name );
501 file = fopen( fullname, "r" );
503 else fullname = xstrdup( name );
505 if (!file) fatal_error( "Cannot open file '%s'\n", fullname );
506 input_file_name = fullname;
507 current_line = 1;
508 return file;
512 /*******************************************************************
513 * close_input_file
515 * Close the current input file (must have been opened with open_input_file).
517 void close_input_file( FILE *file )
519 fclose( file );
520 free( input_file_name );
521 input_file_name = NULL;
522 current_line = 0;
526 /*******************************************************************
527 * open_output_file
529 void open_output_file(void)
531 if (output_file_name)
533 if (strendswith( output_file_name, ".o" ))
534 output_file_source_name = open_temp_output_file( ".s" );
535 else
536 if (!(output_file = fopen( output_file_name, "w" )))
537 fatal_error( "Unable to create output file '%s'\n", output_file_name );
539 else output_file = stdout;
543 /*******************************************************************
544 * close_output_file
546 void close_output_file(void)
548 if (!output_file || !output_file_name) return;
549 if (fclose( output_file ) < 0) fatal_perror( "fclose" );
550 if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
551 output_file = NULL;
555 /*******************************************************************
556 * open_temp_output_file
558 char *open_temp_output_file( const char *suffix )
560 char *tmp_file = make_temp_file( output_file_name, suffix );
561 if (!(output_file = fopen( tmp_file, "w" )))
562 fatal_error( "Unable to create output file '%s'\n", tmp_file );
563 return tmp_file;
567 /*******************************************************************
568 * remove_stdcall_decoration
570 * Remove a possible @xx suffix from a function name.
571 * Return the numerical value of the suffix, or -1 if none.
573 int remove_stdcall_decoration( char *name )
575 char *p, *end = strrchr( name, '@' );
576 if (!end || !end[1] || end == name) return -1;
577 if (target.cpu != CPU_i386) return -1;
578 /* make sure all the rest is digits */
579 for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
580 *end = 0;
581 return atoi( end + 1 );
585 /*******************************************************************
586 * assemble_file
588 * Run a file through the assembler.
590 void assemble_file( const char *src_file, const char *obj_file )
592 struct strarray args = get_as_command();
593 strarray_add( &args, "-o" );
594 strarray_add( &args, obj_file );
595 strarray_add( &args, src_file );
596 spawn( args );
600 /*******************************************************************
601 * alloc_dll_spec
603 * Create a new dll spec file descriptor
605 DLLSPEC *alloc_dll_spec(void)
607 DLLSPEC *spec;
609 spec = xmalloc( sizeof(*spec) );
610 memset( spec, 0, sizeof(*spec) );
611 spec->type = SPEC_WIN32;
612 spec->characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
613 spec->subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
614 spec->subsystem_major = 4;
615 spec->subsystem_minor = 0;
616 spec->dll_characteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT | IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
617 spec->exports.base = MAX_ORDINALS;
618 return spec;
622 static void free_exports( struct exports *entries )
624 free( entries->entry_points );
625 free( entries->names );
626 free( entries->ordinals );
630 /*******************************************************************
631 * free_dll_spec
633 * Free dll spec file descriptor
635 void free_dll_spec( DLLSPEC *spec )
637 int i;
639 for (i = 0; i < spec->nb_entry_points; i++)
641 ORDDEF *odp = &spec->entry_points[i];
642 free( odp->name );
643 free( odp->export_name );
644 free( odp->link_name );
646 free_exports( &spec->exports );
647 free( spec->file_name );
648 free( spec->dll_name );
649 free( spec->c_name );
650 free( spec->init_func );
651 free( spec->entry_points );
652 free( spec->resources );
653 free( spec );
657 /*******************************************************************
658 * make_c_identifier
660 * Map a string to a valid C identifier.
662 char *make_c_identifier( const char *str )
664 char *p, buffer[256];
666 for (p = buffer; *str && p < buffer+sizeof(buffer)-1; p++, str++)
668 if (isalnum(*str)) *p = *str;
669 else *p = '_';
671 *p = 0;
672 return xstrdup( buffer );
676 /*******************************************************************
677 * get_stub_name
679 * Generate an internal name for a stub entry point.
681 const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
683 static char *buffer;
685 free( buffer );
686 if (odp->name || odp->export_name)
688 char *p;
689 buffer = strmake( "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
690 /* make sure name is a legal C identifier */
691 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
692 if (!*p) return buffer;
693 free( buffer );
695 buffer = strmake( "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
696 return buffer;
699 /* return the stdcall-decorated name for an entry point */
700 const char *get_abi_name( const ORDDEF *odp, const char *name )
702 static char *buffer;
703 char *ret;
705 if (target.cpu != CPU_i386) return name;
707 switch (odp->type)
709 case TYPE_STDCALL:
710 if (is_pe())
712 if (odp->flags & FLAG_THISCALL) return name;
713 if (odp->flags & FLAG_FASTCALL) ret = strmake( "@%s@%u", name, get_args_size( odp ));
714 else if (!kill_at) ret = strmake( "%s@%u", name, get_args_size( odp ));
715 else return name;
717 else
719 if (odp->flags & FLAG_THISCALL) ret = strmake( "__thiscall_%s", name );
720 else if (odp->flags & FLAG_FASTCALL) ret = strmake( "__fastcall_%s", name );
721 else return name;
723 break;
725 case TYPE_PASCAL:
726 if (is_pe() && !kill_at)
728 int args = get_args_size( odp );
729 if (odp->flags & FLAG_REGISTER) args += get_ptr_size(); /* context argument */
730 ret = strmake( "%s@%u", name, args );
732 else return name;
733 break;
735 default:
736 return name;
739 free( buffer );
740 buffer = ret;
741 return ret;
744 const char *get_link_name( const ORDDEF *odp )
746 return get_abi_name( odp, odp->link_name );
749 /*******************************************************************
750 * sort_func_list
752 * Sort a list of functions, removing duplicates.
754 int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) )
756 int i, j;
758 if (!count) return 0;
759 qsort( list, count, sizeof(*list), compare );
760 for (i = j = 0; i < count; i++) if (compare( &list[j], &list[i] )) list[++j] = list[i];
761 return j + 1;
765 /* return the page size for the target CPU */
766 unsigned int get_page_size(void)
768 return 0x1000; /* same on all platforms */
771 /* return the total size in bytes of the arguments on the stack */
772 unsigned int get_args_size( const ORDDEF *odp )
774 int i, size;
776 for (i = size = 0; i < odp->u.func.nb_args; i++)
778 switch (odp->u.func.args[i])
780 case ARG_INT64:
781 case ARG_DOUBLE:
782 if (target.cpu == CPU_ARM) size = (size + 7) & ~7;
783 size += 8;
784 break;
785 case ARG_INT128:
786 /* int128 is passed as pointer on x86_64 */
787 if (target.cpu != CPU_x86_64)
789 size += 16;
790 break;
792 /* fall through */
793 default:
794 size += get_ptr_size();
795 break;
798 return size;
801 /* return the assembly name for a C symbol */
802 const char *asm_name( const char *sym )
804 static char *buffer;
806 switch (target.platform)
808 case PLATFORM_MINGW:
809 case PLATFORM_WINDOWS:
810 if (target.cpu != CPU_i386) return sym;
811 if (sym[0] == '@') return sym; /* fastcall */
812 /* fall through */
813 case PLATFORM_APPLE:
814 if (sym[0] == '.' && sym[1] == 'L') return sym;
815 free( buffer );
816 buffer = strmake( "_%s", sym );
817 return buffer;
818 default:
819 return sym;
823 /* return the assembly name for an ARM64/ARM64EC function */
824 const char *arm64_name( const char *sym )
826 if (target.cpu == CPU_ARM64EC) return strmake( "\"#%s\"", sym );
827 return asm_name( sym );
830 /* return an assembly function declaration for a C function name */
831 void output_function_header( const char *func, int global )
833 const char *name = arm64_name( func );
835 output( "\t.text\n" );
837 switch (target.platform)
839 case PLATFORM_APPLE:
840 if (global) output( "\t.globl %s\n\t.private_extern %s\n", name, name );
841 break;
842 case PLATFORM_MINGW:
843 case PLATFORM_WINDOWS:
844 if (target.cpu == CPU_ARM64EC) output( ".section .text,\"xr\",discard,%s\n\t", name );
845 output( "\t.def %s\n\t.scl 2\n\t.type 32\n\t.endef\n", name );
846 if (global) output( "\t.globl %s\n", name );
847 break;
848 default:
849 output( "\t.type %s,@function\n", name );
850 if (global) output( "\t.globl %s\n\t.hidden %s\n", name, name );
851 break;
853 output( "\t.balign 4\n" );
854 output( "%s:\n", name );
857 /* output a size declaration for an assembly function */
858 void output_function_size( const char *name )
860 switch (target.platform)
862 case PLATFORM_APPLE:
863 case PLATFORM_MINGW:
864 case PLATFORM_WINDOWS:
865 break;
866 default:
867 output( "\t.size %s, .-%s\n", name, name );
868 break;
872 /* output a .cfi directive */
873 void output_cfi( const char *format, ... )
875 va_list valist;
877 if (!unwind_tables) return;
878 va_start( valist, format );
879 fputc( '\t', output_file );
880 vfprintf( output_file, format, valist );
881 fputc( '\n', output_file );
882 va_end( valist );
885 /* output a .seh directive */
886 void output_seh( const char *format, ... )
888 va_list valist;
890 if (!is_pe()) return;
891 va_start( valist, format );
892 fputc( '\t', output_file );
893 vfprintf( output_file, format, valist );
894 fputc( '\n', output_file );
895 va_end( valist );
898 /* output an RVA pointer */
899 void output_rva( const char *format, ... )
901 va_list valist;
903 va_start( valist, format );
904 switch (target.platform)
906 case PLATFORM_MINGW:
907 case PLATFORM_WINDOWS:
908 output( "\t.rva " );
909 vfprintf( output_file, format, valist );
910 fputc( '\n', output_file );
911 break;
912 default:
913 output( "\t.long " );
914 vfprintf( output_file, format, valist );
915 output( " - .L__wine_spec_rva_base\n" );
916 break;
918 va_end( valist );
921 /* output an RVA pointer or ordinal for a function thunk */
922 void output_thunk_rva( int ordinal, const char *format, ... )
924 if (ordinal == -1)
926 va_list valist;
928 va_start( valist, format );
929 switch (target.platform)
931 case PLATFORM_MINGW:
932 case PLATFORM_WINDOWS:
933 output( "\t.rva " );
934 vfprintf( output_file, format, valist );
935 fputc( '\n', output_file );
936 if (get_ptr_size() == 8) output( "\t.long 0\n" );
937 break;
938 default:
939 output( "\t%s ", get_asm_ptr_keyword() );
940 vfprintf( output_file, format, valist );
941 output( " - .L__wine_spec_rva_base\n" );
942 break;
944 va_end( valist );
946 else
948 if (get_ptr_size() == 4) output( "\t.long 0x8000%04x\n", ordinal );
949 else output( "\t.quad 0x800000000000%04x\n", ordinal );
953 /* output the GNU note for non-exec stack */
954 void output_gnu_stack_note(void)
956 switch (target.platform)
958 case PLATFORM_MINGW:
959 case PLATFORM_WINDOWS:
960 case PLATFORM_APPLE:
961 break;
962 default:
963 output( "\t.section .note.GNU-stack,\"\",@progbits\n" );
964 break;
968 /* return a global symbol declaration for an assembly symbol */
969 const char *asm_globl( const char *func )
971 static char *buffer;
973 free( buffer );
974 switch (target.platform)
976 case PLATFORM_APPLE:
977 buffer = strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
978 break;
979 case PLATFORM_MINGW:
980 case PLATFORM_WINDOWS:
982 const char *name = asm_name( func );
983 buffer = strmake( "\t.globl %s\n%s:", name, name );
984 break;
986 default:
987 buffer = strmake( "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
988 break;
990 return buffer;
993 const char *get_asm_ptr_keyword(void)
995 switch(get_ptr_size())
997 case 4: return ".long";
998 case 8: return ".quad";
1000 assert(0);
1001 return NULL;
1004 const char *get_asm_string_keyword(void)
1006 switch (target.platform)
1008 case PLATFORM_APPLE:
1009 return ".asciz";
1010 default:
1011 return ".string";
1015 const char *get_asm_export_section(void)
1017 switch (target.platform)
1019 case PLATFORM_APPLE: return ".data";
1020 case PLATFORM_MINGW:
1021 case PLATFORM_WINDOWS: return ".section .edata";
1022 default: return ".section .data";
1026 const char *get_asm_rodata_section(void)
1028 switch (target.platform)
1030 case PLATFORM_APPLE: return ".const";
1031 default: return ".section .rodata";
1035 const char *get_asm_rsrc_section(void)
1037 switch (target.platform)
1039 case PLATFORM_APPLE: return ".data";
1040 case PLATFORM_MINGW:
1041 case PLATFORM_WINDOWS: return ".section .rsrc";
1042 default: return ".section .data";
1046 const char *get_asm_string_section(void)
1048 switch (target.platform)
1050 case PLATFORM_APPLE: return ".cstring";
1051 default: return ".section .rodata";