1/* 2 * Copyright (c) 1999 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 cstring_literals.c. 29 * 30 * The following include files need to be included before this file: 31 * #include "ld.h" 32 * #include "objects.h" 33 */ 34 35/* 36 * The literal_data which is set into a merged_section's literal_data field for 37 * S_CSTRING_LITERALS sections. The external functions declared at the end of 38 * this file operate on this data and are used for the other fields of a 39 * merged_section for literals (literal_merge and literal_write). 40 */ 41struct cstring_data { 42 struct cstring_bucket **hashtable; /* the hash table */ 43 struct cstring_block *cstring_blocks; /* the cstrings */ 44 struct cstring_load_order_data /* the load order info needed to */ 45 *cstring_load_order_data; /* re-merge when using -dead_strip */ 46#ifdef DEBUG 47 unsigned long nfiles; /* number of files with this section */ 48 unsigned long nbytes; /* total number of bytes in the input files*/ 49 /* merged into this section */ 50 unsigned long ninput_strings;/* number of strings in the input file */ 51 unsigned long noutput_strings;/* number of strings in the output file */ 52 unsigned long nprobes; /* number of hash probes */ 53#endif /* DEBUG */ 54}; 55 56/* the number of entries in the hash table */ 57#define CSTRING_HASHSIZE 1022 58 59/* the hash bucket entries in the hash table points to; allocated as needed */ 60struct cstring_bucket { 61 char *cstring; /* pointer to the string */ 62 unsigned long offset; /* offset of this string in the output file */ 63 struct cstring_bucket *next;/* next in the hash chain */ 64}; 65 66/* the blocks that store the strings; allocated as needed */ 67struct cstring_block { 68 unsigned long size; /* the number of bytes in this block */ 69 unsigned long used; /* the number of bytes used in this block */ 70 enum bool full; /* no more strings are to come from this block*/ 71 char *cstrings; /* the strings */ 72 struct cstring_block *next; /* the next block */ 73}; 74 75/* the load order info needed to re-merge when using -dead_strip */ 76struct cstring_load_order_data { 77 char *order_line_buffer; 78 unsigned long ncstring_order_lines; 79 struct cstring_order_line *cstring_order_lines; 80}; 81/* the load order info for a single cstring order line */ 82struct cstring_order_line { 83 unsigned character_index; 84 unsigned long output_offset; 85}; 86 87__private_extern__ void cstring_merge( 88 struct cstring_data *data, 89 struct merged_section *ms, 90 struct section *s, 91 struct section_map *section_map, 92 enum bool redo_live); 93 94__private_extern__ void cstring_order( 95 struct cstring_data *data, 96 struct merged_section *ms); 97 98__private_extern__ void cstring_reset_live( 99 struct cstring_data *data, 100 struct merged_section *ms); 101 102__private_extern__ void get_cstring_from_sectorder( 103 struct merged_section *ms, 104 unsigned long *index, 105 char *buffer, 106 unsigned long line_number, 107 unsigned long char_pos); 108 109__private_extern__ unsigned long lookup_cstring( 110 char *cstring, 111 struct cstring_data *data, 112 struct merged_section *ms); 113 114__private_extern__ void cstring_output( 115 struct cstring_data *data, 116 struct merged_section *ms); 117 118__private_extern__ void cstring_free( 119 struct cstring_data *data); 120 121#ifdef DEBUG 122__private_extern__ void print_cstring_data( 123 struct cstring_data *data, 124 char *indent); 125 126__private_extern__ void cstring_data_stats( 127 struct cstring_data *data, 128 struct merged_section *ms); 129#endif /* DEBUG */ 130