Skip to content

Commit 33f2cf9

Browse files
Added support for GNU Linker Script (#3373)
1 parent 1b1d673 commit 33f2cf9

17 files changed

+319
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+5
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@
507507
"alias": "gni",
508508
"owner": "RunDevelopment"
509509
},
510+
"linker-script": {
511+
"title": "GNU Linker Script",
512+
"alias": "ld",
513+
"owner": "RunDevelopment"
514+
},
510515
"go": {
511516
"title": "Go",
512517
"require": "clike",

components/prism-linker-script.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Prism.languages['linker-script'] = {
2+
'comment': {
3+
pattern: /(^|\s)\/\*[\s\S]*?(?:$|\*\/)/,
4+
lookbehind: true,
5+
greedy: true
6+
},
7+
'identifier': {
8+
pattern: /"[^"\r\n]*"/,
9+
greedy: true
10+
},
11+
12+
'location-counter': {
13+
pattern: /\B\.\B/,
14+
alias: 'important'
15+
},
16+
17+
'section': {
18+
pattern: /(^|[^\w*])\.\w+\b/,
19+
lookbehind: true,
20+
alias: 'keyword'
21+
},
22+
'function': /\b[A-Z][A-Z_]*(?=\s*\()/,
23+
24+
'number': /\b(?:0[xX][a-fA-F0-9]+|\d+)[KM]?\b/,
25+
26+
'operator': />>=?|<<=?|->|\+\+|--|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?/,
27+
'punctuation': /[(){},;]/
28+
};
29+
30+
Prism.languages['ld'] = Prism.languages['linker-script'];

components/prism-linker-script.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-linker-script.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<h2>Full example</h2>
2+
<pre><code>/* Source: https://github.com/stivale/stivale2-barebones/blob/master/kernel/linker.ld */
3+
4+
/* We want the symbol _start to be our entry point */
5+
ENTRY(_start)
6+
7+
/* Define the program headers we want so the bootloader gives us the right */
8+
/* MMU permissions */
9+
PHDRS
10+
{
11+
null PT_NULL FLAGS(0) ; /* Null segment */
12+
text PT_LOAD FLAGS((1 &lt;&lt; 0) | (1 &lt;&lt; 2)) ; /* Execute + Read */
13+
rodata PT_LOAD FLAGS((1 &lt;&lt; 2)) ; /* Read only */
14+
data PT_LOAD FLAGS((1 &lt;&lt; 1) | (1 &lt;&lt; 2)) ; /* Write + Read */
15+
}
16+
17+
SECTIONS
18+
{
19+
/* We wanna be placed in the topmost 2GiB of the address space, for optimisations */
20+
/* and because that is what the stivale2 spec mandates. */
21+
/* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
22+
/* that is the beginning of the region. */
23+
. = 0xffffffff80000000;
24+
25+
.text : {
26+
*(.text .text.*)
27+
} :text
28+
29+
/* Move to the next memory page for .rodata */
30+
. += CONSTANT(MAXPAGESIZE);
31+
32+
/* We place the .stivale2hdr section containing the header in its own section, */
33+
/* and we use the KEEP directive on it to make sure it doesn't get discarded. */
34+
.stivale2hdr : {
35+
KEEP(*(.stivale2hdr))
36+
} :rodata
37+
38+
.rodata : {
39+
*(.rodata .rodata.*)
40+
} :rodata
41+
42+
/* Move to the next memory page for .data */
43+
. += CONSTANT(MAXPAGESIZE);
44+
45+
.data : {
46+
*(.data .data.*)
47+
} :data
48+
49+
.bss : {
50+
*(COMMON)
51+
*(.bss .bss.*)
52+
} :data
53+
}</code></pre>

plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
"gamemakerlanguage": "gml",
200200
"po": "gettext",
201201
"gni": "gn",
202+
"ld": "linker-script",
202203
"go-mod": "go-module",
203204
"hbs": "handlebars",
204205
"hs": "haskell",

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
"glsl": "GLSL",
103103
"gn": "GN",
104104
"gni": "GN",
105+
"linker-script": "GNU Linker Script",
106+
"ld": "GNU Linker Script",
105107
"go-module": "Go module",
106108
"go-mod": "Go module",
107109
"graphql": "GraphQL",

0 commit comments

Comments
 (0)