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