Commit | Line | Data |
---|---|---|
98971e75 MY |
1 | ;;; ld-script.el --- GNU linker script editing mode for Emacs |
2 | ||
114f9c96 | 3 | ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
d91362c9 | 4 | ;; Free Software Foundation, Inc. |
98971e75 MY |
5 | |
6 | ;; Author: Masatake YAMATO<jet@gyve.org> | |
7 | ;; Keywords: languages, faces | |
8 | ||
b8313039 JPW |
9 | ;; This file is part of GNU Emacs. |
10 | ||
b1fc2b50 | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
98971e75 | 12 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
98971e75 | 15 | |
b1fc2b50 | 16 | ;; GNU Emacs is distributed in the hope that it will be useful, |
98971e75 MY |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
98971e75 | 23 | |
b8313039 JPW |
24 | ;;; Commentary: |
25 | ||
26 | ;; Major mode for editing GNU linker (ld) scripts. | |
27 | ||
28 | ;;; Code: | |
98971e75 MY |
29 | |
30 | ;; Custom | |
31 | (defgroup ld-script nil | |
32 | "GNU linker script code editing commands for Emacs." | |
33 | :prefix "ld-script-" | |
34 | :group 'languages) | |
35 | ||
a5d37031 MB |
36 | (defvar ld-script-location-counter-face 'ld-script-location-counter) |
37 | (defface ld-script-location-counter | |
4c344753 | 38 | '((t :weight bold :inherit font-lock-builtin-face)) |
98971e75 MY |
39 | "Face for location counter in GNU ld script." |
40 | :group 'ld-script) | |
41 | ||
42 | ;; Syntax rules | |
b8313039 | 43 | (defvar ld-script-mode-syntax-table |
98971e75 MY |
44 | (let ((st (make-syntax-table))) |
45 | (modify-syntax-entry ?\ "-" st) | |
46 | (modify-syntax-entry ?{ "(}" st) | |
47 | (modify-syntax-entry ?} "){" 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 ?_ "w" 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 | (modify-syntax-entry ?= "." st) | |
59 | (modify-syntax-entry ?* ". 23" st) | |
60 | (modify-syntax-entry ?/ ". 14" st) | |
61 | (modify-syntax-entry ?+ "." st) | |
62 | (modify-syntax-entry ?- "." st) | |
63 | (modify-syntax-entry ?! "." st) | |
64 | (modify-syntax-entry ?~ "." st) | |
65 | (modify-syntax-entry ?% "." st) | |
66 | (modify-syntax-entry ?< "." st) | |
67 | (modify-syntax-entry ?> "." st) | |
68 | (modify-syntax-entry ?& "." st) | |
69 | (modify-syntax-entry ?| "." st) | |
70 | (modify-syntax-entry ?\" "\"" st) | |
71 | st) | |
72 | "Syntax table used while in `ld-script-mode'.") | |
73 | ||
74 | ;; Font lock keywords | |
75ee40be | 75 | ;; (The section number comes from ld's info.) |
b8313039 | 76 | (defvar ld-script-keywords |
75ee40be MY |
77 | '( |
78 | ;; 3.4.1 Setting the Entry Point | |
79 | "ENTRY" | |
80 | ;; 3.4.2 Commands Dealing with Files | |
81 | "INCLUDE" "INPUT" "GROUP" "AS_NEEDED" "OUTPUT" "SEARCH_DIR" "STARTUP" | |
82 | ;; 3.4.3 Commands Dealing with Object File Formats | |
98971e75 | 83 | "OUTPUT_FORMAT" "TARGET" |
75ee40be MY |
84 | ;; 3.4.3 Other Linker Script Commands |
85 | "ASSERT" "EXTERN" "FORCE_COMMON_ALLOCATION" | |
86 | "INHIBIT_COMMON_ALLOCATION" "NOCROSSREFS" "OUTPUT_ARCH" | |
87 | ;; 3.5.2 PROVIDE | |
b8313039 | 88 | "PROVIDE" |
75ee40be | 89 | ;; 3.5.3 PROVIDE_HIDDEN |
5bc1b111 | 90 | "PROVIDE_HIDDEN" |
75ee40be MY |
91 | ;; 3.6 SECTIONS Command |
92 | "SECTIONS" | |
93 | ;; 3.6.4.2 Input Section Wildcard Patterns | |
94 | "SORT" "SORT_BY_NAME" "SORT_BY_ALIGNMENT" | |
95 | ;; 3.6.4.3 Input Section for Common Symbols | |
96 | "COMMON" | |
97 | ;; 3.6.4.4 Input Section and Garbage Collection | |
98 | "KEEP" | |
99 | ;; 3.6.5 Output Section Data | |
100 | "BYTE" "SHORT" "LONG" "QUAD" "SQUAD" "FILL" | |
101 | ;; 3.6.6 Output Section Keywords | |
102 | "CREATE_OBJECT_SYMBOLS" "CONSTRUCTORS" | |
103 | "__CTOR_LIST__" "__CTOR_END__" "__DTOR_LIST__" "__DTOR_END__" | |
104 | ;; 3.6.7 Output Section Discarding | |
105 | ;; See `ld-script-font-lock-keywords' | |
106 | ;; 3.6.8.1 Output Section Type | |
98971e75 | 107 | "NOLOAD" "DSECT" "COPY" "INFO" "OVERLAY" |
75ee40be | 108 | ;; 3.6.8.2 Output Section LMA |
98971e75 | 109 | "AT" |
75ee40be MY |
110 | ;; 3.6.8.4 Forced Input Alignment |
111 | "SUBALIGN" | |
112 | ;; 3.6.8.6 Output Section Phdr | |
113 | ":PHDR" | |
114 | ;; 3.7 MEMORY Command | |
98971e75 | 115 | "MEMORY" |
75ee40be | 116 | ;; 3.8 PHDRS Command |
98971e75 MY |
117 | "PHDRS" "FILEHDR" "FLAGS" |
118 | "PT_NULL" "PT_LOAD" "PT_DYNAMIC" "PT_INTERP" "PT_NONE" "PT_SHLIB" "PT_PHDR" | |
75ee40be | 119 | ;; 3.9 VERSION Command |
98971e75 MY |
120 | "VERSION") |
121 | "Keywords used of GNU ld script.") | |
122 | ||
75ee40be | 123 | ;; 3.10.8 Builtin Functions |
b8313039 JPW |
124 | (defvar ld-script-builtins |
125 | '("ABSOLUTE" | |
98971e75 MY |
126 | "ADDR" |
127 | "ALIGN" | |
128 | "BLOCK" | |
6f9a47ab MY |
129 | "DATA_SEGMENT_ALIGN" |
130 | "DATA_SEGMENT_END" | |
131 | "DATA_SEGMENT_RELRO_END" | |
98971e75 | 132 | "DEFINED" |
75ee40be | 133 | "LENGTH" "len" "l" |
98971e75 MY |
134 | "LOADADDR" |
135 | "MAX" | |
136 | "MIN" | |
137 | "NEXT" | |
75ee40be | 138 | "ORIGIN" "org" "o" |
6f9a47ab | 139 | "SEGMENT_START" |
98971e75 MY |
140 | "SIZEOF" |
141 | "SIZEOF_HEADERS" | |
142 | "sizeof_headers") | |
143 | "Builtin functions of GNU ld script.") | |
144 | ||
145 | (defvar ld-script-font-lock-keywords | |
4076cbf6 MY |
146 | (append |
147 | `((,(regexp-opt ld-script-keywords 'words) | |
148 | 1 font-lock-keyword-face) | |
149 | (,(regexp-opt ld-script-builtins 'words) | |
150 | 1 font-lock-builtin-face) | |
75ee40be MY |
151 | ;; 3.6.7 Output Section Discarding |
152 | ;; 3.6.4.1 Input Section Basics | |
153 | ;; 3.6.8.6 Output Section Phdr | |
154 | ("/DISCARD/\\|EXCLUDE_FILE\\|:NONE" . font-lock-warning-face) | |
4076cbf6 MY |
155 | ("\\W\\(\\.\\)\\W" 1 ld-script-location-counter-face) |
156 | ) | |
157 | cpp-font-lock-keywords) | |
b8313039 | 158 | "Default font-lock-keywords for `ld-script-mode'.") |
98971e75 | 159 | |
4ec7bdfd MY |
160 | ;; Linux-2.6.9 uses some different suffix for linker scripts: |
161 | ;; "ld", "lds", "lds.S", "lds.in", "ld.script", and "ld.script.balo". | |
162 | ;; eCos uses "ld" and "ldi". | |
163 | ;; Netbsd uses "ldscript.*". | |
98971e75 | 164 | ;;;###autoload |
0b7f397c DN |
165 | (add-to-list 'auto-mode-alist (purecopy '("\\.ld[si]?\\>" . ld-script-mode))) |
166 | ;;;###autoload | |
167 | (add-to-list 'auto-mode-alist (purecopy '("ld\\.?script\\>" . ld-script-mode))) | |
4ec7bdfd | 168 | |
4c22303a | 169 | ;;;###autoload |
0b7f397c | 170 | (add-to-list 'auto-mode-alist (purecopy '("\\.x[bdsru]?[cn]?\\'" . ld-script-mode))) |
98971e75 MY |
171 | |
172 | ;;;###autoload | |
173 | (define-derived-mode ld-script-mode nil "LD-Script" | |
174 | "A major mode to edit GNU ld script files" | |
175 | (set (make-local-variable 'comment-start) "/* ") | |
176 | (set (make-local-variable 'comment-end) " */") | |
4c344753 SM |
177 | (set (make-local-variable 'font-lock-defaults) |
178 | '(ld-script-font-lock-keywords nil))) | |
98971e75 | 179 | |
b8313039 JPW |
180 | (provide 'ld-script) |
181 | ||
5f3996dc | 182 | ;; arch-tag: 83280b6b-e6fc-4d00-a630-922d7aec5593 |
98971e75 | 183 | ;;; ld-script.el ends here |