special.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* special.h: Routines to handle special characteristics of the linker
  2. Copyright (C) 2002-2003 Sebastian Reichelt
  3. Copyright (C) 2003 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #ifndef SPECIAL_H
  16. #define SPECIAL_H
  17. #include "generic.h"
  18. #include "data.h"
  19. // Special symbols processed in other files.
  20. #define SYM_OMIT_BSS_INIT "__ld_omit_bss_init"
  21. #define SYM_ALL_RELOCS "__ld_all_relocs"
  22. #define SYM_IGNORE_GLOBAL_IMPORTS "__ld_ignore_global_imports"
  23. // Operators for global imports.
  24. #define SYMOP_NOT "NOT_"
  25. #define SYMOP_AND "_AND_"
  26. // Special symbol prefix for built-in symbols.
  27. #define SYMPF_BUILTIN "__ld_"
  28. // Special symbol prefixes for automatic insertions.
  29. #define SYMPF_INSERT "insert_"
  30. #define SYMPF_BUILTIN_INSERT SYMPF_BUILTIN SYMPF_INSERT
  31. #define SYMPF_COMPRESSED "compressed_"
  32. #define SYMPF_BUILTIN_INSERT_COMPRESSED SYMPF_BUILTIN_INSERT SYMPF_COMPRESSED
  33. #define SYMPF_CALC_CONST "calc_const_"
  34. #define SYMPF_BUILTIN_CALC_CONST SYMPF_BUILTIN SYMPF_CALC_CONST
  35. // Special symbol prefix for nostub comment data.
  36. #define SYMPF_NOSTUB_DATA "_nostub_data__"
  37. // Beginning of the nostub data prefix, so we can call GetExportNumber
  38. // on nostub data symbols by skipping this part.
  39. #define SYMPF_NOSTUB_DATA_START "_nostub_"
  40. // Special symbol resolving to hardware ID.
  41. #define SYM_BUILTIN_HARDWARE_ID SYMPF_BUILTIN "hardware_id"
  42. // Try to translate an external symbol into a special-feature symbol used by the linker.
  43. // If the symbol contains a number, it is written to the variable pointed to by Number.
  44. typedef enum {ST_NORMAL = 0, ST_ROM_CALL, ST_RAM_CALL, ST_EXTRA_RAM, ST_LIB_CALL} SpecialExternalSymbolTypes;
  45. SpecialExternalSymbolTypes TranslateSpecialExternalSymbol (PROGRAM *Program, char *SymbolName, void **Reference, OFFSET *Number);
  46. // Handle the symbol if it is a special one.
  47. // Returns TRUE if it was special; in this case it should not be used.
  48. BOOLEAN HandleSpecialSymbol (PROGRAM *Program, const char *SymbolName);
  49. // Translate a section name into a startup section number.
  50. // Returns 0 if the name does not represent a startup section.
  51. OFFSET GetStartupSectionNumber (const char *SectionName, SIZE MaxLen);
  52. // Translate a symbol name into the number of an exported function, if the
  53. // function is meant to be exported.
  54. // Returns -1 if it is not an exported function.
  55. OFFSET GetExportNumber (const char *SymbolName);
  56. // Add all imports with names defined by this program, if they are needed.
  57. // For example, they can add code to support constructors and destructors,
  58. // BSS blocks, etc.
  59. BOOLEAN CreateSpecialGlobalImports (PROGRAM *Program);
  60. // If the reloc or its relation point to a special ld-exported symbol,
  61. // change it to the appropriate value if possible. FALSE is returned
  62. // only if it is not a special symbol reloc, or if there was an error.
  63. BOOLEAN ResolveSpecialSymbolReloc (RELOC *Reloc, BOOLEAN *TryAgain);
  64. // If the reloc points to a special ld-exported symbol, change it to the
  65. // appropriate value if possible. FALSE is returned only if it is not a
  66. // special symbol reloc, or if there was an error.
  67. BOOLEAN ResolveSpecialSymbolRelocTarget (RELOC *Reloc, BOOLEAN *TryAgain);
  68. // If the reloc's relation points to a special ld-exported symbol,
  69. // change it to the appropriate value if possible. FALSE is returned
  70. // only if it is not a special symbol location, or if there was an error.
  71. BOOLEAN ResolveSpecialSymbolRelocRelation (RELOC *Reloc, BOOLEAN *TryAgain);
  72. // If the location points to a special ld-exported symbol, change it to the
  73. // appropriate value if possible. FALSE is returned only if it is not a
  74. // special symbol location, or if there was an error.
  75. // Warning: If the special symbol resolves to a number, Location->Symbol and
  76. // Location->SymbolName will both be NULL, and Location->Offset will contain
  77. // the number.
  78. BOOLEAN ResolveSpecialSymbolLocation (SECTION *Section, LOCATION *Location, BOOLEAN *TryAgain);
  79. // Count the items for a specific built-in symbol, specified by SymName
  80. // and SymNameLength. If TrueValue is nonzero, items are not counted,
  81. // but NewValue is set to this value if at least one item was found. In
  82. // that case, if Program->ResolveAllBuiltins is false, NewValue may be
  83. // unchanged even though there are some items; you need to check back
  84. // later when Program->ResolveAllBuiltins is true.
  85. BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLength, OFFSET *NewValue, OFFSET TrueValue);
  86. // Check if the given location points to a calculator-specific builtin
  87. // symbol.
  88. BOOLEAN IsCalcBuiltinLocation (const LOCATION *Location);
  89. // Return whether the reloc can be resolved to a calculator-specific value.
  90. // ResolveSpecialSymbol or something related must have been called on the
  91. // reloc at least once.
  92. BOOLEAN IsPlainCalcBuiltin (const RELOC *Reloc);
  93. // If the location can be resolved to a calculator-specific value, get the
  94. // value for the specified calculator.
  95. // If IsCalcBuiltinLocation returned a positive result for this reloc, this
  96. // function will not return a negative result.
  97. BOOLEAN GetCalcBuiltinLocationValue (const LOCATION *Location, ProgramCalcs DestCalc, IMAX *Value);
  98. // If the reloc can be resolved to a calculator-specific value, get the
  99. // value for the specified calculator.
  100. // The return value is the same as for IsPlainCalcBuiltin.
  101. BOOLEAN GetCalcBuiltinValue (const RELOC *Reloc, ProgramCalcs DestCalc, IMAX *Value);
  102. // If required by some special symbol(s) in the section, modify the
  103. // contents of the section.
  104. // This can be used to insert special items such as relocation entries.
  105. // MergedSection specifies the (usually large) part of the program that
  106. // has already been merged.
  107. // If necessary, MergedSection is frozen automatically.
  108. BOOLEAN HandleSectionContents (SECTION *Section, SECTION *MergedSection);
  109. // Insert contents for an insertion specified by SymbolName, and return
  110. // a symbol from where the insertion took place.
  111. // If necessary, MergedSection is frozen automatically.
  112. SYMBOL *HandleAutoInsertion (SECTION *Section, const char *SymbolName);
  113. // Handle an insertion by cutting the section off at the specified location
  114. // and inserting the contents specified by the name, taking into account
  115. // that MergedSection specifies the (usually large) part of the program
  116. // that has already been merged.
  117. BOOLEAN HandleInsertion (SECTION *Section, OFFSET Location, const char *Name, SECTION *MergedSection, BOOLEAN AlwaysTerminate);
  118. // Append the data required by an insertion (specified by name) to the
  119. // section specified by Section, taking into account that MergedSection
  120. // specifies the (usually large) part of the program that has already
  121. // been merged.
  122. BOOLEAN AppendInsertionData (SECTION *Section, const char *Name, SECTION *MergedSection, BOOLEAN AlwaysTerminate);
  123. #endif