Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 1 | .. _design: |
| 2 | |
| 3 | Linker Design |
| 4 | ============= |
| 5 | |
| 6 | Introduction |
| 7 | ------------ |
| 8 | |
| 9 | lld is a new generation of linker. It is not "section" based like traditional |
| 10 | linkers which mostly just interlace sections from multiple object files into the |
| 11 | output file. Instead, lld is based on "Atoms". Traditional section based |
| 12 | linking work well for simple linking, but their model makes advanced linking |
| 13 | features difficult to implement. Features like dead code stripping, reordering |
| 14 | functions for locality, and C++ coalescing require the linker to work at a finer |
| 15 | grain. |
| 16 | |
| 17 | An atom is an indivisible chunk of code or data. An atom has a set of |
| 18 | attributes, such as: name, scope, content-type, alignment, etc. An atom also |
| 19 | has a list of References. A Reference contains: a kind, an optional offset, an |
| 20 | optional addend, and an optional target atom. |
| 21 | |
| 22 | The Atom model allows the linker to use standard graph theory models for linking |
| 23 | data structures. Each atom is a node, and each Reference is an edge. The |
| 24 | feature of dead code stripping is implemented by following edges to mark all |
| 25 | live atoms, and then delete the non-live atoms. |
| 26 | |
| 27 | |
| 28 | Atom Model |
| 29 | ---------- |
| 30 | |
Michael J. Spencer | aa53d68 | 2012-04-25 19:59:06 +0000 | [diff] [blame] | 31 | An atom is an indivisible chunk of code or data. Typically each user written |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 32 | function or global variable is an atom. In addition, the compiler may emit |
| 33 | other atoms, such as for literal c-strings or floating point constants, or for |
| 34 | runtime data structures like dwarf unwind info or pointers to initializers. |
| 35 | |
| 36 | A simple "hello world" object file would be modeled like this: |
| 37 | |
| 38 | .. image:: hello.png |
| 39 | |
| 40 | There are three atoms: main, a proxy for printf, and an anonymous atom |
| 41 | containing the c-string literal "hello world". The Atom "main" has two |
| 42 | references. One is the call site for the call to printf, and the other is a |
Michael J. Spencer | aa53d68 | 2012-04-25 19:59:06 +0000 | [diff] [blame] | 43 | reference for the instruction that loads the address of the c-string literal. |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 44 | |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 45 | There are only four different types of atoms: |
| 46 | |
| 47 | * DefinedAtom |
| 48 | 95% of all atoms. This is a chunk of code or data |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 49 | |
| 50 | * UndefinedAtom |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 51 | This is a place holder in object files for a reference to some atom |
| 52 | outside the translation unit.During core linking it is usually replaced |
| 53 | by (coalesced into) another Atom. |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 54 | |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 55 | * SharedLibraryAtom |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 56 | If a required symbol name turns out to be defined in a dynamic shared |
| 57 | library (and not some object file). A SharedLibraryAtom is the |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 58 | placeholder Atom used to represent that fact. |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 59 | |
| 60 | It is similar to an UndefinedAtom, but it also tracks information |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 61 | about the associated shared library. |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 62 | |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 63 | * AbsoluteAtom |
| 64 | This is for embedded support where some stuff is implemented in ROM at |
| 65 | some fixed address. This atom has no content. It is just an address |
Alex Rosenberg | b65e888 | 2013-02-03 07:05:26 +0000 | [diff] [blame] | 66 | that the Writer needs to fix up any references to point to. |
Marshall Clow | 341f496 | 2012-07-18 23:20:40 +0000 | [diff] [blame] | 67 | |
| 68 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 69 | File Model |
| 70 | ---------- |
| 71 | |
| 72 | The linker views the input files as basically containers of Atoms and |
| 73 | References, and just a few attributes of their own. The linker works with three |
| 74 | kinds of files: object files, static libraries, and dynamic shared libraries. |
| 75 | Each kind of file has reader object which presents the file in the model |
| 76 | expected by the linker. |
| 77 | |
| 78 | Object File |
| 79 | ~~~~~~~~~~~ |
| 80 | |
| 81 | An object file is just a container of atoms. When linking an object file, a |
| 82 | reader is instantiated which parses the object file and instantiates a set of |
| 83 | atoms representing all content in the .o file. The linker adds all those atoms |
| 84 | to a master graph. |
| 85 | |
| 86 | Static Library (Archive) |
| 87 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | |
| 89 | This is the traditional unix static archive which is just a collection of object |
| 90 | files with a "table of contents". When linking with a static library, by default |
| 91 | nothing is added to the master graph of atoms. Instead, if after merging all |
| 92 | atoms from object files into a master graph, if any "undefined" atoms are left |
| 93 | remaining in the master graph, the linker reads the table of contents for each |
| 94 | static library to see if any have the needed definitions. If so, the set of |
| 95 | atoms from the specified object file in the static library is added to the |
| 96 | master graph of atoms. |
| 97 | |
| 98 | Dynamic Library (Shared Object) |
| 99 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 100 | |
| 101 | Dynamic libraries are different than object files and static libraries in that |
| 102 | they don't directly add any content. Their purpose is to check at build time |
| 103 | that the remaining undefined references can be resolved at runtime, and provide |
| 104 | a list of dynamic libraries (SO_NEEDED) that will be needed at runtime. The way |
| 105 | this is modeled in the linker is that a dynamic library contributes no atoms to |
| 106 | the initial graph of atoms. Instead, (like static libraries) if there are |
| 107 | "undefined" atoms in the master graph of all atoms, then each dynamic library is |
| 108 | checked to see if exports the required symbol. If so, a "shared library" atom is |
| 109 | instantiated by the by the reader which the linker uses to replace the |
| 110 | "undefined" atom. |
| 111 | |
| 112 | Linking Steps |
| 113 | ------------- |
| 114 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 115 | Through the use of abstract Atoms, the core of linking is architecture |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 116 | independent and file format independent. All command line parsing is factored |
| 117 | out into a separate "options" abstraction which enables the linker to be driven |
| 118 | with different command line sets. |
| 119 | |
| 120 | The overall steps in linking are: |
| 121 | |
| 122 | #. Command line processing |
| 123 | |
| 124 | #. Parsing input files |
| 125 | |
| 126 | #. Resolving |
| 127 | |
| 128 | #. Passes/Optimizations |
| 129 | |
| 130 | #. Generate output file |
| 131 | |
| 132 | The Resolving and Passes steps are done purely on the master graph of atoms, so |
| 133 | they have no notion of file formats such as mach-o or ELF. |
| 134 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 135 | |
| 136 | Input Files |
| 137 | ~~~~~~~~~~~ |
| 138 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 139 | Existing developer tools using different file formats for object files. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 140 | A goal of lld is to be file format independent. This is done |
| 141 | through a plug-in model for reading object files. The lld::Reader is the base |
| 142 | class for all object file readers. A Reader follows the factory method pattern. |
| 143 | A Reader instantiates an lld::File object (which is a graph of Atoms) from a |
| 144 | given object file (on disk or in-memory). |
| 145 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 146 | Every Reader subclass defines its own "options" class (for instance the mach-o |
| 147 | Reader defines the class ReaderOptionsMachO). This options class is the |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 148 | one-and-only way to control how the Reader operates when parsing an input file |
| 149 | into an Atom graph. For instance, you may want the Reader to only accept |
| 150 | certain architectures. The options class can be instantiated from command |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 151 | line options, or it can be subclassed and the ivars programmatically set. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 152 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 153 | Resolving |
| 154 | ~~~~~~~~~ |
| 155 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 156 | The resolving step takes all the atoms' graphs from each object file and |
| 157 | combines them into one master object graph. Unfortunately, it is not as simple |
| 158 | as appending the atom list from each file into one big list. There are many |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 159 | cases where atoms need to be coalesced. That is, two or more atoms need to be |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 160 | coalesced into one atom. This is necessary to support: C language "tentative |
| 161 | definitions", C++ weak symbols for templates and inlines defined in headers, |
| 162 | replacing undefined atoms with actual definition atoms, and for merging copies |
| 163 | of constants like c-strings and floating point constants. |
| 164 | |
| 165 | The linker support coalescing by-name and by-content. By-name is used for |
| 166 | tentative definitions and weak symbols. By-content is used for constant data |
| 167 | that can be merged. |
| 168 | |
| 169 | The resolving process maintains some global linking "state", including a "symbol |
| 170 | table" which is a map from llvm::StringRef to lld::Atom*. With these data |
Gabor Greif | c52fc9e | 2012-04-25 21:09:37 +0000 | [diff] [blame] | 171 | structures, the linker iterates all atoms in all input files. For each atom, it |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 172 | checks if the atom is named and has a global or hidden scope. If so, the atom |
| 173 | is added to the symbol table map. If there already is a matching atom in that |
| 174 | table, that means the current atom needs to be coalesced with the found atom, or |
| 175 | it is a multiple definition error. |
| 176 | |
| 177 | When all initial input file atoms have been processed by the resolver, a scan is |
| 178 | made to see if there are any undefined atoms in the graph. If there are, the |
| 179 | linker scans all libraries (both static and dynamic) looking for definitions to |
| 180 | replace the undefined atoms. It is an error if any undefined atoms are left |
| 181 | remaining. |
| 182 | |
| 183 | Dead code stripping (if requested) is done at the end of resolving. The linker |
| 184 | does a simple mark-and-sweep. It starts with "root" atoms (like "main" in a main |
| 185 | executable) and follows each references and marks each Atom that it visits as |
| 186 | "live". When done, all atoms not marked "live" are removed. |
| 187 | |
| 188 | The result of the Resolving phase is the creation of an lld::File object. The |
Nick Kledzik | bb963df | 2012-04-18 21:55:06 +0000 | [diff] [blame] | 189 | goal is that the lld::File model is **the** internal representation |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 190 | throughout the linker. The file readers parse (mach-o, ELF, COFF) into an |
| 191 | lld::File. The file writers (mach-o, ELF, COFF) taken an lld::File and produce |
| 192 | their file kind, and every Pass only operates on an lld::File. This is not only |
| 193 | a simpler, consistent model, but it enables the state of the linker to be dumped |
| 194 | at any point in the link for testing purposes. |
| 195 | |
| 196 | |
| 197 | Passes |
| 198 | ~~~~~~ |
| 199 | |
| 200 | The Passes step is an open ended set of routines that each get a change to |
| 201 | modify or enhance the current lld::File object. Some example Passes are: |
| 202 | |
| 203 | * stub (PLT) generation |
| 204 | |
| 205 | * GOT instantiation |
| 206 | |
| 207 | * order_file optimization |
| 208 | |
| 209 | * branch island generation |
| 210 | |
| 211 | * branch shim generation |
| 212 | |
| 213 | * Objective-C optimizations (Darwin specific) |
| 214 | |
| 215 | * TLV instantiation (Darwin specific) |
| 216 | |
Alex Rosenberg | b65e888 | 2013-02-03 07:05:26 +0000 | [diff] [blame] | 217 | * DTrace probe processing (Darwin specific) |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 218 | |
| 219 | * compact unwind encoding (Darwin specific) |
| 220 | |
| 221 | |
| 222 | Some of these passes are specific to Darwin's runtime environments. But many of |
| 223 | the passes are applicable to any OS (such as generating branch island for out of |
| 224 | range branch instructions). |
| 225 | |
| 226 | The general structure of a pass is to iterate through the atoms in the current |
| 227 | lld::File object, inspecting each atom and doing something. For instance, the |
| 228 | stub pass, looks for call sites to shared library atoms (e.g. call to printf). |
| 229 | It then instantiates a "stub" atom (PLT entry) and a "lazy pointer" atom for |
| 230 | each proxy atom needed, and these new atoms are added to the current lld::File |
| 231 | object. Next, all the noted call sites to shared library atoms have their |
| 232 | References altered to point to the stub atom instead of the shared library atom. |
| 233 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 234 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 235 | Generate Output File |
| 236 | ~~~~~~~~~~~~~~~~~~~~ |
| 237 | |
| 238 | Once the passes are done, the output file writer is given current lld::File |
| 239 | object. The writer's job is to create the executable content file wrapper and |
| 240 | place the content of the atoms into it. |
| 241 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 242 | lld uses a plug-in model for writing output files. All concrete writers (e.g. |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 243 | ELF, mach-o, etc) are subclasses of the lld::Writer class. |
Nick Kledzik | bb963df | 2012-04-18 21:55:06 +0000 | [diff] [blame] | 244 | |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 245 | Unlike the Reader class which has just one method to instantiate an lld::File, |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 246 | the Writer class has multiple methods. The crucial method is to generate the |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 247 | output file, but there are also methods which allow the Writer to contribute |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 248 | Atoms to the resolver and specify passes to run. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 249 | |
| 250 | An example of contributing |
| 251 | atoms is that if the Writer knows a main executable is being linked and such |
| 252 | an executable requires a specially named entry point (e.g. "_main"), the Writer |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 253 | can add an UndefinedAtom with that special name to the resolver. This will |
| 254 | cause the resolver to issue an error if that symbol is not defined. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 255 | |
| 256 | Sometimes a Writer supports lazily created symbols, such as names for the start |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 257 | of sections. To support this, the Writer can create a File object which vends |
| 258 | no initial atoms, but does lazily supply atoms by name as needed. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 259 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 260 | Every Writer subclass defines its own "options" class (for instance the mach-o |
| 261 | Writer defines the class WriterOptionsMachO). This options class is the |
| 262 | one-and-only way to control how the Writer operates when producing an output |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 263 | file from an Atom graph. For instance, you may want the Writer to optimize |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 264 | the output for certain OS versions, or strip local symbols, etc. The options |
| 265 | class can be instantiated from command line options, or it can be subclassed |
| 266 | and the ivars programmatically set. |
Nick Kledzik | bb963df | 2012-04-18 21:55:06 +0000 | [diff] [blame] | 267 | |
| 268 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 269 | lld::File representations |
| 270 | ------------------------- |
| 271 | |
Rui Ueyama | aa7b304 | 2015-04-10 21:23:51 +0000 | [diff] [blame] | 272 | Just as LLVM has three representations of its IR model, lld has two |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 273 | representations of its File/Atom/Reference model: |
| 274 | |
| 275 | * In memory, abstract C++ classes (lld::Atom, lld::Reference, and lld::File). |
| 276 | |
| 277 | * textual (in YAML) |
| 278 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 279 | |
| 280 | Textual representations in YAML |
| 281 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 282 | |
| 283 | In designing a textual format we want something easy for humans to read and easy |
| 284 | for the linker to parse. Since an atom has lots of attributes most of which are |
| 285 | usually just the default, we should define default values for every attribute so |
| 286 | that those can be omitted from the text representation. Here is the atoms for a |
| 287 | simple hello world program expressed in YAML:: |
| 288 | |
| 289 | target-triple: x86_64-apple-darwin11 |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 290 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 291 | atoms: |
| 292 | - name: _main |
| 293 | scope: global |
| 294 | type: code |
| 295 | content: [ 55, 48, 89, e5, 48, 8d, 3d, 00, 00, 00, 00, 30, c0, e8, 00, 00, |
| 296 | 00, 00, 31, c0, 5d, c3 ] |
| 297 | fixups: |
| 298 | - offset: 07 |
| 299 | kind: pcrel32 |
| 300 | target: 2 |
| 301 | - offset: 0E |
| 302 | kind: call32 |
| 303 | target: _fprintf |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 304 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 305 | - type: c-string |
| 306 | content: [ 73, 5A, 00 ] |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 307 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 308 | ... |
| 309 | |
| 310 | The biggest use for the textual format will be writing test cases. Writing test |
| 311 | cases in C is problematic because the compiler may vary its output over time for |
| 312 | its own optimization reasons which my inadvertently disable or break the linker |
| 313 | feature trying to be tested. By writing test cases in the linkers own textual |
| 314 | format, we can exactly specify every attribute of every atom and thus target |
| 315 | specific linker logic. |
| 316 | |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 317 | The textual/YAML format follows the ReaderWriter patterns used in lld. The lld |
| 318 | library comes with the classes: ReaderYAML and WriterYAML. |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 319 | |
| 320 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 321 | Testing |
Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 322 | ------- |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 323 | |
| 324 | The lld project contains a test suite which is being built up as new code is |
| 325 | added to lld. All new lld functionality should have a tests added to the test |
| 326 | suite. The test suite is `lit <http://llvm.org/cmds/lit.html/>`_ driven. Each |
| 327 | test is a text file with comments telling lit how to run the test and check the |
| 328 | result To facilitate testing, the lld project builds a tool called lld-core. |
| 329 | This tool reads a YAML file (default from stdin), parses it into one or more |
| 330 | lld::File objects in memory and then feeds those lld::File objects to the |
Rui Ueyama | adafac6 | 2015-04-09 20:43:38 +0000 | [diff] [blame] | 331 | resolver phase. |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 332 | |
| 333 | |
| 334 | Resolver testing |
| 335 | ~~~~~~~~~~~~~~~~ |
| 336 | |
| 337 | Basic testing is the "core linking" or resolving phase. That is where the |
| 338 | linker merges object files. All test cases are written in YAML. One feature of |
| 339 | YAML is that it allows multiple "documents" to be encoding in one YAML stream. |
| 340 | That means one text file can appear to the linker as multiple .o files - the |
| 341 | normal case for the linker. |
| 342 | |
| 343 | Here is a simple example of a core linking test case. It checks that an |
| 344 | undefined atom from one file will be replaced by a definition from another |
| 345 | file:: |
| 346 | |
| 347 | # RUN: lld-core %s | FileCheck %s |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 348 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 349 | # |
| 350 | # Test that undefined atoms are replaced with defined atoms. |
| 351 | # |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 352 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 353 | --- |
| 354 | atoms: |
| 355 | - name: foo |
| 356 | definition: undefined |
| 357 | --- |
| 358 | atoms: |
| 359 | - name: foo |
| 360 | scope: global |
| 361 | type: code |
| 362 | ... |
Shankar Easwaran | 3d8de47 | 2014-01-27 03:09:26 +0000 | [diff] [blame] | 363 | |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 364 | # CHECK: name: foo |
| 365 | # CHECK: scope: global |
| 366 | # CHECK: type: code |
| 367 | # CHECK-NOT: name: foo |
| 368 | # CHECK: ... |
| 369 | |
| 370 | |
| 371 | Passes testing |
| 372 | ~~~~~~~~~~~~~~ |
| 373 | |
| 374 | Since Passes just operate on an lld::File object, the lld-core tool has the |
| 375 | option to run a particular pass (after resolving). Thus, you can write a YAML |
| 376 | test case with carefully crafted input to exercise areas of a Pass and the check |
| 377 | the resulting lld::File object as represented in YAML. |
| 378 | |
| 379 | |
| 380 | Design Issues |
| 381 | ------------- |
| 382 | |
| 383 | There are a number of open issues in the design of lld. The plan is to wait and |
| 384 | make these design decisions when we need to. |
| 385 | |
| 386 | |
| 387 | Debug Info |
| 388 | ~~~~~~~~~~ |
| 389 | |
| 390 | Currently, the lld model says nothing about debug info. But the most popular |
| 391 | debug format is DWARF and there is some impedance mismatch with the lld model |
| 392 | and DWARF. In lld there are just Atoms and only Atoms that need to be in a |
| 393 | special section at runtime have an associated section. Also, Atoms do not have |
| 394 | addresses. The way DWARF is spec'ed different parts of DWARF are supposed to go |
| 395 | into specially named sections and the DWARF references function code by address. |
| 396 | |
| 397 | CPU and OS specific functionality |
| 398 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 399 | |
| 400 | Currently, lld has an abstract "Platform" that deals with any CPU or OS specific |
| 401 | differences in linking. We just keep adding virtual methods to the base |
| 402 | Platform class as we find linking areas that might need customization. At some |
| 403 | point we'll need to structure this better. |
| 404 | |
| 405 | |
| 406 | File Attributes |
| 407 | ~~~~~~~~~~~~~~~ |
| 408 | |
| 409 | Currently, lld::File just has a path and a way to iterate its atoms. We will |
Gabor Greif | c52fc9e | 2012-04-25 21:09:37 +0000 | [diff] [blame] | 410 | need to add more attributes on a File. For example, some equivalent to the |
Daniel Dunbar | 5969411 | 2012-04-06 21:02:24 +0000 | [diff] [blame] | 411 | target triple. There is also a number of cached or computed attributes that |
| 412 | could make various Passes more efficient. For instance, on Darwin there are a |
| 413 | number of Objective-C optimizations that can be done by a Pass. But it would |
| 414 | improve the plain C case if the Objective-C optimization Pass did not have to |
| 415 | scan all atoms looking for any Objective-C data structures. This could be done |
| 416 | if the lld::File object had an attribute that said if the file had any |
| 417 | Objective-C data in it. The Resolving phase would then be required to "merge" |
| 418 | that attribute as object files are added. |