ld-script.el 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ;;; ld-script.el --- GNU linker script editing mode for Emacs
  2. ;; Copyright (C) 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Masatake YAMATO<jet@gyve.org>
  4. ;; Keywords: languages, faces
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Major mode for editing GNU linker (ld) scripts.
  18. ;;; Code:
  19. ;; Custom
  20. (defgroup ld-script nil
  21. "GNU linker script code editing commands for Emacs."
  22. :prefix "ld-script-"
  23. :group 'languages)
  24. (defvar ld-script-location-counter-face 'ld-script-location-counter)
  25. (defface ld-script-location-counter
  26. '((t :weight bold :inherit font-lock-builtin-face))
  27. "Face for location counter in GNU ld script."
  28. :group 'ld-script)
  29. ;; Syntax rules
  30. (defvar ld-script-mode-syntax-table
  31. (let ((st (make-syntax-table)))
  32. (modify-syntax-entry ?\ "-" st)
  33. (modify-syntax-entry ?{ "(}" st)
  34. (modify-syntax-entry ?} "){" st)
  35. (modify-syntax-entry ?\( "()" st)
  36. (modify-syntax-entry ?\) ")(" st)
  37. (modify-syntax-entry ?\[ "(]" st)
  38. (modify-syntax-entry ?\] ")[" st)
  39. (modify-syntax-entry ?_ "w" st)
  40. (modify-syntax-entry ?. "_" st)
  41. (modify-syntax-entry ?\\ "\\" st)
  42. (modify-syntax-entry ?: "." st)
  43. (modify-syntax-entry ?, "." st)
  44. (modify-syntax-entry ?? "." st)
  45. (modify-syntax-entry ?= "." st)
  46. (modify-syntax-entry ?* ". 23" st)
  47. (modify-syntax-entry ?/ ". 14" st)
  48. (modify-syntax-entry ?+ "." st)
  49. (modify-syntax-entry ?- "." st)
  50. (modify-syntax-entry ?! "." st)
  51. (modify-syntax-entry ?~ "." st)
  52. (modify-syntax-entry ?% "." st)
  53. (modify-syntax-entry ?< "." st)
  54. (modify-syntax-entry ?> "." st)
  55. (modify-syntax-entry ?& "." st)
  56. (modify-syntax-entry ?| "." st)
  57. (modify-syntax-entry ?\" "\"" st)
  58. st)
  59. "Syntax table used while in `ld-script-mode'.")
  60. ;; Font lock keywords
  61. ;; (The section number comes from ld's info.)
  62. (defvar ld-script-keywords
  63. '(
  64. ;; 3.4.1 Setting the Entry Point
  65. "ENTRY"
  66. ;; 3.4.2 Commands Dealing with Files
  67. "INCLUDE" "INPUT" "GROUP" "AS_NEEDED" "OUTPUT" "SEARCH_DIR" "STARTUP"
  68. ;; 3.4.3 Commands Dealing with Object File Formats
  69. "OUTPUT_FORMAT" "TARGET"
  70. ;; 3.4.4 Assign alias names to memory regions
  71. "REGION_ALIAS"
  72. ;; 3.4.5 Other Linker Script Commands
  73. "ASSERT" "EXTERN" "FORCE_COMMON_ALLOCATION"
  74. "INHIBIT_COMMON_ALLOCATION" "INSERT" "AFTER" "BEFORE"
  75. "NOCROSSREFS" "OUTPUT_ARCH" "LD_FEATURE"
  76. ;; 3.5.2 PROVIDE
  77. "PROVIDE"
  78. ;; 3.5.3 PROVIDE_HIDDEN
  79. "PROVIDE_HIDDEN"
  80. ;; 3.6 SECTIONS Command
  81. "SECTIONS"
  82. ;; 3.6.4.2 Input Section Wildcard Patterns
  83. "SORT" "SORT_BY_NAME" "SORT_BY_ALIGNMENT" "SORT_BY_INIT_PRIORITY"
  84. ;; 3.6.4.3 Input Section for Common Symbols
  85. "COMMON"
  86. ;; 3.6.4.4 Input Section and Garbage Collection
  87. "KEEP"
  88. ;; 3.6.5 Output Section Data
  89. "BYTE" "SHORT" "LONG" "QUAD" "SQUAD" "FILL"
  90. ;; 3.6.6 Output Section Keywords
  91. "CREATE_OBJECT_SYMBOLS" "CONSTRUCTORS"
  92. "__CTOR_LIST__" "__CTOR_END__" "__DTOR_LIST__" "__DTOR_END__"
  93. ;; 3.6.7 Output Section Discarding
  94. ;; See `ld-script-font-lock-keywords'
  95. ;; 3.6.8.1 Output Section Type
  96. "NOLOAD" "DSECT" "COPY" "INFO" "OVERLAY"
  97. ;; 3.6.8.2 Output Section LMA
  98. "AT"
  99. ;; 3.6.8.4 Forced Input Alignment
  100. "SUBALIGN"
  101. ;; 3.6.8.5 Output Section Constraint
  102. "ONLY_IF_RO" "ONLY_IF_RW"
  103. ;; 3.6.8.7 Output Section Phdr
  104. ":PHDR"
  105. ;; 3.7 MEMORY Command
  106. "MEMORY"
  107. ;; 3.8 PHDRS Command
  108. "PHDRS" "FILEHDR" "FLAGS"
  109. "PT_NULL" "PT_LOAD" "PT_DYNAMIC" "PT_INTERP" "PT_NOTE" "PT_SHLIB" "PT_PHDR"
  110. ;; 3.9 VERSION Command
  111. "VERSION")
  112. "Keywords used of GNU ld script.")
  113. ;; 3.10.2 Symbolic Constants
  114. ;; 3.10.9 Builtin Functions
  115. (defvar ld-script-builtins
  116. '("CONSTANT"
  117. "MAXPAGESIZE"
  118. "COMMONPAGESIZE"
  119. "ABSOLUTE"
  120. "ADDR"
  121. "ALIGN"
  122. "ALIGNOF"
  123. "BLOCK"
  124. "DATA_SEGMENT_ALIGN"
  125. "DATA_SEGMENT_END"
  126. "DATA_SEGMENT_RELRO_END"
  127. "DEFINED"
  128. "LENGTH" "len" "l"
  129. "LOADADDR"
  130. "MAX"
  131. "MIN"
  132. "NEXT"
  133. "ORIGIN" "org" "o"
  134. "SEGMENT_START"
  135. "SIZEOF"
  136. "SIZEOF_HEADERS"
  137. "sizeof_headers")
  138. "Builtin functions of GNU ld script.")
  139. (defvar ld-script-font-lock-keywords
  140. (append
  141. `((,(regexp-opt ld-script-keywords 'words)
  142. 1 font-lock-keyword-face)
  143. (,(regexp-opt ld-script-builtins 'words)
  144. 1 font-lock-builtin-face)
  145. ;; 3.6.7 Output Section Discarding
  146. ;; 3.6.4.1 Input Section Basics
  147. ;; 3.6.8.7 Output Section Phdr
  148. ("/DISCARD/\\|EXCLUDE_FILE\\|:NONE" . font-lock-warning-face)
  149. ("\\W\\(\\.\\)\\W" 1 ld-script-location-counter-face)
  150. )
  151. cpp-font-lock-keywords)
  152. "Default font-lock-keywords for `ld-script-mode'.")
  153. ;;;###autoload
  154. (define-derived-mode ld-script-mode prog-mode "LD-Script"
  155. "A major mode to edit GNU ld script files"
  156. (set (make-local-variable 'comment-start) "/* ")
  157. (set (make-local-variable 'comment-end) " */")
  158. (set (make-local-variable 'font-lock-defaults)
  159. '(ld-script-font-lock-keywords nil)))
  160. (provide 'ld-script)
  161. ;;; ld-script.el ends here