1/* 2 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#if defined(__MWERKS__) && !defined(__private_extern__) 24#define __private_extern__ __declspec(private_extern) 25#endif 26 27/* 28 * Global types, variables and routines declared in the file ld.c. 29 * 30 * The following include file need to be included before this file: 31 * #include <sys/loader.h> 32 * #include <mach.h> 33 * #include <stdarg.h> (included in <stdio.h>) 34 */ 35 36/* Type for the possible levels of stripping, in increasing order */ 37enum strip_levels { 38 STRIP_NONE, 39 STRIP_DUP_INCLS, 40 STRIP_L_SYMBOLS, 41 STRIP_MIN_DEBUG, 42 STRIP_DEBUG, 43 STRIP_NONGLOBALS, 44 STRIP_DYNAMIC_EXECUTABLE, 45 STRIP_ALL 46}; 47 48/* The error level check for undefined symbols */ 49enum undefined_check_level { 50 UNDEFINED_ERROR, 51 UNDEFINED_WARNING, 52 UNDEFINED_SUPPRESS, 53 UNDEFINED_DYNAMIC_LOOKUP, 54 UNDEFINED_DEFINE_A_WAY 55}; 56 57/* The error level check for (twolevel namespace) multiply defined symbols */ 58enum multiply_defined_check_level { 59 MULTIPLY_DEFINED_ERROR, 60 MULTIPLY_DEFINED_WARNING, 61 MULTIPLY_DEFINED_SUPPRESS 62}; 63 64/* The error level check for read only relocs */ 65enum read_only_reloc_check_level { 66 READ_ONLY_RELOC_ERROR, 67 READ_ONLY_RELOC_WARNING, 68 READ_ONLY_RELOC_SUPPRESS 69}; 70 71/* The error level check for section difference relocs */ 72enum sect_diff_reloc_check_level { 73 SECT_DIFF_RELOC_ERROR, 74 SECT_DIFF_RELOC_WARNING, 75 SECT_DIFF_RELOC_SUPPRESS 76}; 77 78/* The error handling for weak reference mismatches */ 79enum weak_reference_mismatches_handling { 80 WEAK_REFS_MISMATCH_ERROR, 81 WEAK_REFS_MISMATCH_WEAK, 82 WEAK_REFS_MISMATCH_NON_WEAK 83}; 84 85__private_extern__ struct macosx_deployment_target macosx_deployment_target; 86 87/* name of this program as executed (argv[0]) */ 88__private_extern__ char *progname; 89/* indication of an error set in error(), for processing a number of errors 90 and then exiting */ 91__private_extern__ unsigned long errors; 92/* the pagesize of the machine this program is running on, getpagesize() value*/ 93__private_extern__ unsigned long host_pagesize; 94/* the byte sex of the machine this program is running on */ 95__private_extern__ enum byte_sex host_byte_sex; 96 97/* name of output file */ 98__private_extern__ char *outputfile; 99/* type of output file */ 100__private_extern__ unsigned long filetype; 101/* multi or single module dylib output */ 102__private_extern__ enum bool multi_module_dylib; 103 104/* 105 * The architecture of the output file as specified by -arch and the cputype 106 * and cpusubtype of the object files being loaded which will be the output 107 * cputype and cpusubtype. specific_arch_flag is true if an -arch flag is 108 * specified and the flag for a specific implementation of an architecture. 109 */ 110__private_extern__ struct arch_flag arch_flag; 111__private_extern__ enum bool specific_arch_flag; 112 113/* 114 * The -force_cpusubtype_ALL flag. 115 */ 116__private_extern__ enum bool force_cpusubtype_ALL; 117 118/* the byte sex of the output file */ 119__private_extern__ enum byte_sex target_byte_sex; 120 121__private_extern__ 122enum bool trace; /* print stages of link-editing */ 123__private_extern__ 124enum bool save_reloc; /* save relocation information */ 125__private_extern__ 126enum bool output_for_dyld; /* produce output for use with dyld */ 127__private_extern__ 128enum bool bind_at_load; /* mark the output for dyld to be bound 129 when loaded */ 130__private_extern__ 131enum bool no_fix_prebinding; /* mark the output for dyld to never 132 run fix_prebinding */ 133__private_extern__ 134enum bool load_map; /* print a load map */ 135__private_extern__ 136enum bool define_comldsyms; /* define common and link-editor defined 137 symbol reguardless of file type */ 138__private_extern__ 139enum bool seglinkedit; /* create the link edit segment */ 140__private_extern__ 141enum bool whyload; /* print why archive members are 142 loaded */ 143__private_extern__ 144enum bool flush; /* Use the output_flush routine to flush 145 output file by pages */ 146__private_extern__ 147enum bool sectorder_detail; /* print sectorder warnings in detail */ 148__private_extern__ 149enum bool nowarnings; /* suppress warnings */ 150__private_extern__ 151enum bool no_arch_warnings; /* suppress wrong arch warnings */ 152__private_extern__ 153enum bool arch_errors_fatal; /* cause wrong arch errors to be fatal */ 154__private_extern__ 155enum bool archive_ObjC; /* objective-C archive semantics */ 156__private_extern__ 157enum bool archive_all; /* always load everything in archives */ 158__private_extern__ 159enum bool keep_private_externs; /* don't turn private externs into 160 non-external symbols */ 161/* TRUE if -dynamic is specified, FALSE if -static is specified */ 162__private_extern__ enum bool dynamic; 163 164/* The level of symbol table stripping */ 165__private_extern__ enum strip_levels strip_level; 166/* Strip the base file symbols (the -A argument's symbols) */ 167__private_extern__ enum bool strip_base_symbols; 168 169/* strip dead blocks */ 170__private_extern__ enum bool dead_strip; 171/* don't strip module init and term sections */ 172__private_extern__ enum bool no_dead_strip_inits_and_terms; 173/* print timings for dead striping code */ 174__private_extern__ enum bool dead_strip_times; 175 176#ifndef RLD 177/* 178 * Data structures to perform selective exporting of global symbols. 179 * save_symbols is the names of the symbols from -exported_symbols_list 180 * remove_symbols is the names of the symbols from -unexported_symbols_list 181 */ 182__private_extern__ struct symbol_list *save_symbols; 183__private_extern__ uint32_t nsave_symbols; 184__private_extern__ struct symbol_list *remove_symbols; 185__private_extern__ uint32_t nremove_symbols; 186 187/* 188 * -executable_path option's argument, executable_path is used to replace 189 * "@executable_path for dependent libraries. 190 */ 191__private_extern__ char *executable_path; 192#endif /* RLD */ 193 194/* The list of symbols to be traced */ 195__private_extern__ char **trace_syms; 196__private_extern__ unsigned long ntrace_syms; 197 198/* The number of references of undefined symbols to print */ 199__private_extern__ unsigned long Yflag; 200 201/* The list of allowed undefined symbols */ 202__private_extern__ char **undef_syms; 203__private_extern__ unsigned long nundef_syms; 204 205/* The list of -dylib_file arguments */ 206__private_extern__ char **dylib_files; 207__private_extern__ unsigned long ndylib_files; 208 209/* The checking for undefined symbols */ 210__private_extern__ enum undefined_check_level undefined_flag; 211 212/* The checking for (twolevel namespace) multiply defined symbols */ 213__private_extern__ enum multiply_defined_check_level 214 multiply_defined_flag; 215__private_extern__ enum multiply_defined_check_level 216 multiply_defined_unused_flag; 217/* the -nomultidefs option */ 218__private_extern__ enum bool nomultidefs; 219 220/* The checking for read only relocs */ 221__private_extern__ enum read_only_reloc_check_level read_only_reloc_flag; 222 223/* The checking for pic relocs */ 224__private_extern__ enum sect_diff_reloc_check_level sect_diff_reloc_flag; 225 226/* The handling for weak reference mismatches */ 227__private_extern__ enum weak_reference_mismatches_handling 228 weak_reference_mismatches; 229 230/* The prebinding optimization */ 231__private_extern__ enum bool prebinding; 232__private_extern__ enum bool prebind_allow_overlap; 233__private_extern__ enum bool prebind_all_twolevel_modules; 234 235/* True if -m is specified to allow multiply symbols, as a warning */ 236__private_extern__ enum bool allow_multiply_defined_symbols; 237 238/* The segment alignment */ 239__private_extern__ unsigned long segalign; 240#ifndef RLD 241__private_extern__ enum bool segalign_specified; 242#endif /* !defined(RLD) */ 243/* The size of pagezero from the -pagezero_size flag */ 244__private_extern__ unsigned long pagezero_size; 245/* The maximum segment alignment allowed to be specified, in hex */ 246#define MAXSEGALIGN 0x8000 247/* The default section alignment */ 248__private_extern__ unsigned long defaultsectalign; 249/* The maximum section alignment allowed to be specified, as a power of two */ 250#define MAXSECTALIGN 15 /* 2**15 or 0x8000 */ 251/* The default section alignment if not specified, as a power of two */ 252#define DEFAULTSECTALIGN 4 /* 2**4 or 16 */ 253 254/* The first segment address */ 255__private_extern__ unsigned long seg1addr; 256__private_extern__ enum bool seg1addr_specified; 257 258/* read-only and read-write segment addresses */ 259__private_extern__ unsigned long segs_read_only_addr; 260__private_extern__ enum bool segs_read_only_addr_specified; 261__private_extern__ unsigned long segs_read_write_addr; 262__private_extern__ enum bool segs_read_write_addr_specified; 263 264/* The stack address and size */ 265__private_extern__ unsigned long stack_addr; 266__private_extern__ enum bool stack_addr_specified; 267__private_extern__ unsigned long stack_size; 268__private_extern__ enum bool stack_size_specified; 269 270/* TRUE if -allow_stack_execute is specified */ 271__private_extern__ enum bool allow_stack_execute; 272 273/* The header pad */ 274__private_extern__ unsigned long headerpad; 275/* 276 * If specified makes sure the header pad is big enough to change all the 277 * install name of the dylibs in the output to MAXPATHLEN. 278 */ 279__private_extern__ enum bool headerpad_max_install_names; 280 281/* The name of the specified entry point */ 282__private_extern__ char *entry_point_name; 283 284/* The name of the specified library initialization routine */ 285__private_extern__ char *init_name; 286 287/* The dylib information */ 288__private_extern__ char *dylib_install_name; 289__private_extern__ uint32_t dylib_current_version; 290__private_extern__ uint32_t dylib_compatibility_version; 291 292/* the umbrella/sub framework information */ 293__private_extern__ enum bool sub_framework; 294__private_extern__ enum bool umbrella_framework; 295__private_extern__ char *sub_framework_name; 296__private_extern__ char *umbrella_framework_name; 297__private_extern__ char *client_name; 298__private_extern__ char **allowable_clients; 299__private_extern__ unsigned long nallowable_clients; 300 301/* The list of sub_umbrella frameworks */ 302__private_extern__ char **sub_umbrellas; 303__private_extern__ unsigned long nsub_umbrellas; 304 305/* The list of sub_library dynamic libraries */ 306__private_extern__ char **sub_librarys; 307__private_extern__ unsigned long nsub_librarys; 308 309/* The dylinker information */ 310__private_extern__ char *dylinker_install_name; 311 312/* set to TRUE if -private_bundle is specified */ 313__private_extern__ enum bool private_bundle; 314 315/* The value of the environment variable NEXT_ROOT */ 316__private_extern__ char *next_root; 317 318/* TRUE if the environment variable LD_TRACE_ARCHIVES 319 (or temporarily RC_TRACE_ARCHIVES) is set */ 320__private_extern__ enum bool ld_trace_archives; 321 322/* TRUE if the environment variable LD_TRACE_DYLIBS 323 (or temporarily RC_TRACE_DYLIBS) is set */ 324__private_extern__ enum bool ld_trace_dylibs; 325 326/* TRUE if the environment variable LD_TRACE_PREBINDING_DISABLED 327 (or temporarily RC_TRACE_PREBINDING_DISABLED) is set */ 328__private_extern__ enum bool ld_trace_prebinding_disabled; 329 330/* the argument to -final_output if any */ 331__private_extern__ char *final_output; 332 333/* The variables to support namespace options */ 334__private_extern__ enum bool namespace_specified; 335__private_extern__ enum bool twolevel_namespace; 336__private_extern__ enum bool force_flat_namespace; 337 338__private_extern__ enum bool twolevel_namespace_hints; 339 340__private_extern__ void *allocate( 341 unsigned long size); 342__private_extern__ void *reallocate( 343 void *, 344 unsigned long size); 345__private_extern__ unsigned long rnd( 346 unsigned long v, 347 unsigned long r); 348__private_extern__ void tell_ProjectBuilder( 349 char *message); 350__private_extern__ void print( 351 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 352__private_extern__ void ld_trace( 353 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 354__private_extern__ void vprint( 355 const char *format, va_list ap); 356__private_extern__ void warning( 357 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 358__private_extern__ void error( 359 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 360__private_extern__ void fatal( 361 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 362__private_extern__ void warning_with_cur_obj( 363 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 364__private_extern__ void error_with_cur_obj( 365 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 366__private_extern__ void system_warning( 367 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 368__private_extern__ void system_error( 369 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 370__private_extern__ void system_fatal( 371 const char *format, ...) __attribute__ ((format (printf, 1, 2))); 372__private_extern__ void mach_fatal( 373 kern_return_t r, 374 char *format, ...) __attribute__ ((format (printf, 2, 3))); 375 376#ifdef DEBUG 377__private_extern__ unsigned long debug; /* link-editor debugging */ 378#endif /* DEBUG */ 379