special.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* special.h: Routines to handle special characteristics of the linker
  2. Copyright (C) 2002-2003 Sebastian Reichelt
  3. Copyright (C) 2003-2005 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_MLINK "mlink_"
  34. #define SYMPF_BUILTIN_INSERT_MLINK SYMPF_BUILTIN_INSERT SYMPF_MLINK
  35. #define SYMPF_CALC_CONST "calc_const_"
  36. #define SYMPF_BUILTIN_CALC_CONST SYMPF_BUILTIN SYMPF_CALC_CONST
  37. // Special symbol prefix for nostub comment data.
  38. #define SYMPF_NOSTUB_DATA "_nostub_data__"
  39. // Beginning of the nostub data prefix, so we can call GetExportNumber
  40. // on nostub data symbols by skipping this part.
  41. #define SYMPF_NOSTUB_DATA_START "_nostub_"
  42. // Special symbol resolving to hardware ID.
  43. #define SYM_BUILTIN_HARDWARE_ID SYMPF_BUILTIN "hardware_id"
  44. // Try to translate an external symbol into a special-feature symbol used by the linker.
  45. // If the symbol contains a number, it is written to the variable pointed to by Number.
  46. typedef enum {ST_NORMAL = 0, ST_ROM_CALL, ST_RAM_CALL, ST_EXTRA_RAM, ST_LIB_CALL} SpecialExternalSymbolTypes;
  47. SpecialExternalSymbolTypes TranslateSpecialExternalSymbol (PROGRAM *Program, char *SymbolName, void **Reference, OFFSET *Number);
  48. // Handle the symbol if it is a special one.
  49. // Returns TRUE if it was special; in this case it should not be used.
  50. BOOLEAN HandleSpecialSymbol (PROGRAM *Program, const char *SymbolName);
  51. // Translate a section name into a startup section number.
  52. // Returns 0 if the name does not represent a startup section.
  53. OFFSET GetStartupSectionNumber (const char *SectionName, SIZE MaxLen);
  54. // Translate a symbol name into the number of an exported function, if the
  55. // function is meant to be exported.
  56. // Returns -1 if it is not an exported function.
  57. OFFSET GetExportNumber (const char *SymbolName);
  58. // Add all imports with names defined by this program, if they are needed.
  59. // For example, they can add code to support constructors and destructors,
  60. // BSS blocks, etc.
  61. BOOLEAN CreateSpecialGlobalImports (PROGRAM *Program);
  62. // If the reloc or its relation point to a special ld-exported symbol,
  63. // change it to the appropriate value if possible. FALSE is returned
  64. // only if it is not a special symbol reloc, or if there was an error.
  65. BOOLEAN ResolveSpecialSymbolReloc (RELOC *Reloc, BOOLEAN *TryAgain);
  66. // If the reloc points to a special ld-exported symbol, change it to the
  67. // appropriate value if possible. FALSE is returned only if it is not a
  68. // special symbol reloc, or if there was an error.
  69. BOOLEAN ResolveSpecialSymbolRelocTarget (RELOC *Reloc, BOOLEAN *TryAgain);
  70. // If the reloc's relation points to a special ld-exported symbol,
  71. // change it to the appropriate value if possible. FALSE is returned
  72. // only if it is not a special symbol location, or if there was an error.
  73. BOOLEAN ResolveSpecialSymbolRelocRelation (RELOC *Reloc, BOOLEAN *TryAgain);
  74. // If the location points to a special ld-exported symbol, change it to the
  75. // appropriate value if possible. FALSE is returned only if it is not a
  76. // special symbol location, or if there was an error.
  77. // Warning: If the special symbol resolves to a number, Location->Symbol and
  78. // Location->SymbolName will both be NULL, and Location->Offset will contain
  79. // the number.
  80. BOOLEAN ResolveSpecialSymbolLocation (SECTION *Section, LOCATION *Location, BOOLEAN *TryAgain);
  81. // Count the items for a specific built-in symbol, specified by SymName
  82. // and SymNameLength. If TrueValue is nonzero, items are not counted,
  83. // but NewValue is set to this value if at least one item was found. In
  84. // that case, if Program->ResolveAllBuiltins is false, NewValue may be
  85. // unchanged even though there are some items; you need to check back
  86. // later when Program->ResolveAllBuiltins is true.
  87. BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLength, OFFSET *NewValue, OFFSET TrueValue);
  88. // Check if the given location points to a calculator-specific builtin
  89. // symbol.
  90. BOOLEAN IsCalcBuiltinLocation (const LOCATION *Location);
  91. // Return whether the reloc can be resolved to a calculator-specific value.
  92. // ResolveSpecialSymbol or something related must have been called on the
  93. // reloc at least once.
  94. BOOLEAN IsPlainCalcBuiltin (const RELOC *Reloc);
  95. // If the location can be resolved to a calculator-specific value, get the
  96. // value for the specified calculator.
  97. // If IsCalcBuiltinLocation returned a positive result for this reloc, this
  98. // function will not return a negative result.
  99. BOOLEAN GetCalcBuiltinLocationValue (const LOCATION *Location, ProgramCalcs DestCalc, IMAX *Value);
  100. // If the reloc can be resolved to a calculator-specific value, get the
  101. // value for the specified calculator.
  102. // The return value is the same as for IsPlainCalcBuiltin.
  103. BOOLEAN GetCalcBuiltinValue (const RELOC *Reloc, ProgramCalcs DestCalc, IMAX *Value);
  104. // If required by some special symbol(s) in the section, modify the
  105. // contents of the section.
  106. // This can be used to insert special items such as relocation entries.
  107. // MergedSection specifies the (usually large) part of the program that
  108. // has already been merged.
  109. // If necessary, MergedSection is frozen automatically.
  110. BOOLEAN HandleSectionContents (SECTION *Section, SECTION *MergedSection);
  111. // Insert contents for an insertion specified by SymbolName, and return
  112. // a symbol from where the insertion took place.
  113. // If necessary, MergedSection is frozen automatically.
  114. SYMBOL *HandleAutoInsertion (SECTION *Section, const char *SymbolName);
  115. // Handle an insertion by cutting the section off at the specified location
  116. // and inserting the contents specified by the name, taking into account
  117. // that MergedSection specifies the (usually large) part of the program
  118. // that has already been merged.
  119. BOOLEAN HandleInsertion (SECTION *Section, OFFSET Location, const char *Name, SECTION *MergedSection, BOOLEAN AlwaysTerminate);
  120. // Append the data required by an insertion (specified by name) to the
  121. // section specified by Section, taking into account that MergedSection
  122. // specifies the (usually large) part of the program that has already
  123. // been merged.
  124. BOOLEAN AppendInsertionData (SECTION *Section, const char *Name, SECTION *MergedSection, BOOLEAN AlwaysTerminate);
  125. #endif