Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 1 | //===- Core/Resolver.cpp - Resolves Atom References -----------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lld/Core/Resolver.h" |
| 11 | #include "lld/Core/Atom.h" |
| 12 | #include "lld/Core/File.h" |
| 13 | #include "lld/Core/InputFiles.h" |
| 14 | #include "lld/Core/SymbolTable.h" |
| 15 | #include "lld/Core/UndefinedAtom.h" |
| 16 | #include "lld/Platform/Platform.h" |
| 17 | |
| 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <cassert> |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 22 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
| 25 | namespace lld { |
| 26 | |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 27 | /// This is used as a filter function to std::remove_if to dead strip atoms. |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 28 | class NotLive { |
| 29 | public: |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 30 | NotLive(const llvm::DenseSet<const Atom*>& la) : _liveAtoms(la) { } |
| 31 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 32 | bool operator()(const Atom *atom) const { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 33 | // don't remove if live |
| 34 | if ( _liveAtoms.count(atom) ) |
| 35 | return false; |
Nick Kledzik | 23384e8 | 2012-02-07 02:59:54 +0000 | [diff] [blame] | 36 | // don't remove if marked never-dead-strip |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 37 | if ( const DefinedAtom* defAtom = atom->definedAtom() ) { |
| 38 | if ( defAtom->deadStrip() == DefinedAtom::deadStripNever ) |
| 39 | return false; |
| 40 | } |
| 41 | // do remove this atom |
| 42 | return true; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 43 | } |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | const llvm::DenseSet<const Atom*> _liveAtoms; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 49 | |
| 50 | /// This is used as a filter function to std::remove_if to coalesced atoms. |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 51 | class AtomCoalescedAway { |
| 52 | public: |
| 53 | AtomCoalescedAway(SymbolTable &sym) : _symbolTable(sym) {} |
| 54 | |
| 55 | bool operator()(const Atom *atom) const { |
| 56 | const Atom *rep = _symbolTable.replacement(atom); |
| 57 | return rep != atom; |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | SymbolTable &_symbolTable; |
| 62 | }; |
| 63 | |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 67 | void Resolver::initializeState() { |
| 68 | _platform.initialize(); |
| 69 | } |
| 70 | |
| 71 | // add initial undefines from -u option |
| 72 | void Resolver::addInitialUndefines() { |
| 73 | |
| 74 | } |
| 75 | |
| 76 | // add all atoms from all initial .o files |
| 77 | void Resolver::buildInitialAtomList() { |
| 78 | // each input files contributes initial atoms |
| 79 | _atoms.reserve(1024); |
| 80 | _inputFiles.forEachInitialAtom(*this); |
| 81 | |
| 82 | _completedInitialObjectFiles = true; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | // called before the first atom in any file is added with doAtom() |
| 87 | void Resolver::doFile(const File &file) { |
| 88 | // notify platform |
| 89 | _platform.fileAdded(file); |
| 90 | } |
| 91 | |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 92 | |
| 93 | void Resolver::doUndefinedAtom(const class UndefinedAtom& atom) { |
| 94 | // add to list of known atoms |
| 95 | _atoms.push_back(&atom); |
| 96 | |
| 97 | // tell symbol table |
| 98 | _symbolTable.add(atom); |
| 99 | } |
| 100 | |
| 101 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 102 | // called on each atom when a file is added |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 103 | void Resolver::doDefinedAtom(const DefinedAtom &atom) { |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 104 | // notify platform |
| 105 | _platform.atomAdded(atom); |
| 106 | |
| 107 | // add to list of known atoms |
| 108 | _atoms.push_back(&atom); |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 109 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 110 | // adjust scope (e.g. force some globals to be hidden) |
| 111 | _platform.adjustScope(atom); |
| 112 | |
| 113 | // non-static atoms need extra handling |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 114 | if (atom.scope() != DefinedAtom::scopeTranslationUnit) { |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 115 | // tell symbol table about non-static atoms |
| 116 | _symbolTable.add(atom); |
| 117 | |
| 118 | // platform can add aliases for any symbol |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 119 | std::vector<const DefinedAtom *> aliases; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 120 | if (_platform.getAliasAtoms(atom, aliases)) |
| 121 | this->addAtoms(aliases); |
| 122 | } |
| 123 | |
| 124 | if (_platform.deadCodeStripping()) { |
| 125 | // add to set of dead-strip-roots, all symbols that |
| 126 | // the compiler marks as don't strip |
| 127 | if (!atom.deadStrip()) |
| 128 | _deadStripRoots.insert(&atom); |
| 129 | |
| 130 | // add to set of dead-strip-roots, all symbols that |
| 131 | // the platform decided must remain |
| 132 | if (_platform.isDeadStripRoot(atom)) |
| 133 | _deadStripRoots.insert(&atom); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // utility to add a vector of atoms |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 138 | void Resolver::addAtoms(const std::vector<const DefinedAtom*>& newAtoms) { |
| 139 | for (std::vector<const DefinedAtom *>::const_iterator it = newAtoms.begin(); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 140 | it != newAtoms.end(); ++it) { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 141 | this->doDefinedAtom(**it); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | // ask symbol table if any definitionUndefined atoms still exist |
| 146 | // if so, keep searching libraries until no more atoms being added |
| 147 | void Resolver::resolveUndefines() { |
| 148 | const bool searchArchives = |
| 149 | _platform.searchArchivesToOverrideTentativeDefinitions(); |
| 150 | const bool searchDylibs = |
| 151 | _platform.searchSharedLibrariesToOverrideTentativeDefinitions(); |
| 152 | |
| 153 | // keep looping until no more undefines were added in last loop |
| 154 | unsigned int undefineGenCount = 0xFFFFFFFF; |
| 155 | while (undefineGenCount != _symbolTable.size()) { |
| 156 | undefineGenCount = _symbolTable.size(); |
| 157 | std::vector<const Atom *> undefines; |
| 158 | _symbolTable.undefines(undefines); |
| 159 | for (std::vector<const Atom *>::iterator it = undefines.begin(); |
| 160 | it != undefines.end(); ++it) { |
| 161 | llvm::StringRef undefName = (*it)->name(); |
| 162 | // load for previous undefine may also have loaded this undefine |
| 163 | if (!_symbolTable.isDefined(undefName)) { |
| 164 | _inputFiles.searchLibraries(undefName, true, true, false, *this); |
| 165 | |
| 166 | // give platform a chance to instantiate platform |
| 167 | // specific atoms (e.g. section boundary) |
| 168 | if (!_symbolTable.isDefined(undefName)) { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 169 | std::vector<const DefinedAtom *> platAtoms; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 170 | if (_platform.getPlatformAtoms(undefName, platAtoms)) |
| 171 | this->addAtoms(platAtoms); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | // search libraries for overrides of common symbols |
| 176 | if (searchArchives || searchDylibs) { |
| 177 | std::vector<const Atom *> tents; |
| 178 | for (std::vector<const Atom *>::iterator ait = _atoms.begin(); |
| 179 | ait != _atoms.end(); ++ait) { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 180 | if ( const DefinedAtom* defAtom = (*ait)->definedAtom() ) { |
| 181 | if ( defAtom->merge() == DefinedAtom::mergeAsTentative ) |
| 182 | tents.push_back(defAtom); |
| 183 | } |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 184 | } |
| 185 | for (std::vector<const Atom *>::iterator dit = tents.begin(); |
| 186 | dit != tents.end(); ++dit) { |
| 187 | // load for previous tentative may also have loaded |
| 188 | // this tentative, so check again |
| 189 | llvm::StringRef tentName = (*dit)->name(); |
| 190 | const Atom *curAtom = _symbolTable.findByName(tentName); |
| 191 | assert(curAtom != NULL); |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 192 | if ( const DefinedAtom* curDefAtom = curAtom->definedAtom() ) { |
| 193 | if (curDefAtom->merge() == DefinedAtom::mergeAsTentative ) |
| 194 | _inputFiles.searchLibraries(tentName, searchDylibs, |
| 195 | true, true, *this); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame^] | 202 | // helper to update targets for use with forEachReference() |
| 203 | class ReferenceUpdater : public DefinedAtom::ReferenceHandler { |
| 204 | public: |
| 205 | ReferenceUpdater(SymbolTable& sym) : _symbolTable(sym) { } |
| 206 | |
| 207 | virtual void doReference(const Reference& ref) { |
| 208 | const Atom* newTarget = _symbolTable.replacement(ref.target()); |
| 209 | (const_cast<Reference*>(&ref))->setTarget(newTarget); |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | SymbolTable& _symbolTable; |
| 214 | }; |
| 215 | |
| 216 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 217 | // switch all references to undefined or coalesced away atoms |
| 218 | // to the new defined atom |
| 219 | void Resolver::updateReferences() { |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame^] | 220 | ReferenceUpdater updater(_symbolTable); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 221 | for (std::vector<const Atom *>::iterator it = _atoms.begin(); |
| 222 | it != _atoms.end(); ++it) { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 223 | if ( const DefinedAtom* defAtom = (*it)->definedAtom() ) { |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame^] | 224 | defAtom->forEachReference(updater); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame^] | 229 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 230 | // for dead code stripping, recursively mark atom "live" |
| 231 | void Resolver::markLive(const Atom &atom, WhyLiveBackChain *previous) { |
| 232 | // if -why_live cares about this symbol, then dump chain |
| 233 | if ((previous->referer != NULL) && _platform.printWhyLive(atom.name())) { |
Nick Kledzik | f46669c | 2011-12-21 23:29:36 +0000 | [diff] [blame] | 234 | llvm::errs() << atom.name() << " from " << atom.file().path() << "\n"; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 235 | int depth = 1; |
| 236 | for (WhyLiveBackChain *p = previous; p != NULL; |
| 237 | p = p->previous, ++depth) { |
| 238 | for (int i = depth; i > 0; --i) |
| 239 | llvm::errs() << " "; |
| 240 | llvm::errs() << p->referer->name() << " from " |
Nick Kledzik | f46669c | 2011-12-21 23:29:36 +0000 | [diff] [blame] | 241 | << p->referer->file().path() << "\n"; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | // if already marked live, then done (stop recursion) |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 246 | if ( _liveAtoms.count(&atom) ) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 247 | return; |
| 248 | |
| 249 | // mark this atom is live |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 250 | _liveAtoms.insert(&atom); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 251 | |
| 252 | // mark all atoms it references as live |
| 253 | WhyLiveBackChain thisChain; |
| 254 | thisChain.previous = previous; |
| 255 | thisChain.referer = &atom; |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 256 | if ( const DefinedAtom* defAtom = atom.definedAtom() ) { |
Nick Kledzik | 49d6cc8 | 2012-02-15 00:38:09 +0000 | [diff] [blame^] | 257 | MarkLiveReferences markRefs(*this, &thisChain); |
| 258 | defAtom->forEachReference(markRefs); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | // remove all atoms not actually used |
| 263 | void Resolver::deadStripOptimize() { |
| 264 | // only do this optimization with -dead_strip |
| 265 | if (!_platform.deadCodeStripping()) |
| 266 | return; |
| 267 | |
| 268 | // clear liveness on all atoms |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 269 | _liveAtoms.clear(); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 270 | |
| 271 | // add entry point (main) to live roots |
| 272 | const Atom *entry = this->entryPoint(); |
| 273 | if (entry != NULL) |
| 274 | _deadStripRoots.insert(entry); |
| 275 | |
| 276 | // add -exported_symbols_list, -init, and -u entries to live roots |
| 277 | for (Platform::UndefinesIterator uit = _platform.initialUndefinesBegin(); |
| 278 | uit != _platform.initialUndefinesEnd(); ++uit) { |
| 279 | llvm::StringRef sym = *uit; |
| 280 | const Atom *symAtom = _symbolTable.findByName(sym); |
| 281 | assert(symAtom->definition() != Atom::definitionUndefined); |
| 282 | _deadStripRoots.insert(symAtom); |
| 283 | } |
| 284 | |
| 285 | // add platform specific helper atoms |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 286 | std::vector<const DefinedAtom *> platRootAtoms; |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 287 | if (_platform.getImplicitDeadStripRoots(platRootAtoms)) |
| 288 | this->addAtoms(platRootAtoms); |
| 289 | |
| 290 | // mark all roots as live, and recursively all atoms they reference |
| 291 | for (std::set<const Atom *>::iterator it = _deadStripRoots.begin(); |
| 292 | it != _deadStripRoots.end(); ++it) { |
| 293 | WhyLiveBackChain rootChain; |
| 294 | rootChain.previous = NULL; |
| 295 | rootChain.referer = *it; |
| 296 | this->markLive(**it, &rootChain); |
| 297 | } |
| 298 | |
| 299 | // now remove all non-live atoms from _atoms |
| 300 | _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 301 | NotLive(_liveAtoms)), _atoms.end()); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // error out if some undefines remain |
| 305 | void Resolver::checkUndefines(bool final) { |
| 306 | // when using LTO, undefines are checked after bitcode is optimized |
| 307 | if (_haveLLVMObjs && !final) |
| 308 | return; |
| 309 | |
| 310 | // build vector of remaining undefined symbols |
| 311 | std::vector<const Atom *> undefinedAtoms; |
| 312 | _symbolTable.undefines(undefinedAtoms); |
| 313 | if (_platform.deadCodeStripping()) { |
| 314 | // when dead code stripping we don't care if dead atoms are undefined |
| 315 | undefinedAtoms.erase(std::remove_if( |
| 316 | undefinedAtoms.begin(), undefinedAtoms.end(), |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 317 | NotLive(_liveAtoms)), undefinedAtoms.end()); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | // let platform make error message about missing symbols |
| 321 | if (undefinedAtoms.size() != 0) |
| 322 | _platform.errorWithUndefines(undefinedAtoms, _atoms); |
| 323 | } |
| 324 | |
| 325 | // remove from _atoms all coaleseced away atoms |
| 326 | void Resolver::removeCoalescedAwayAtoms() { |
| 327 | _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), |
| 328 | AtomCoalescedAway(_symbolTable)), _atoms.end()); |
| 329 | } |
| 330 | |
| 331 | // check for interactions between symbols defined in this linkage unit |
| 332 | // and same symbol name in linked dynamic shared libraries |
| 333 | void Resolver::checkDylibSymbolCollisions() { |
| 334 | for (std::vector<const Atom *>::const_iterator it = _atoms.begin(); |
| 335 | it != _atoms.end(); ++it) { |
Nick Kledzik | f4fb2c5 | 2012-01-11 01:06:19 +0000 | [diff] [blame] | 336 | const DefinedAtom* defAtom = (*it)->definedAtom(); |
| 337 | if ( defAtom == NULL ) |
| 338 | continue; |
| 339 | if ( defAtom->merge() != DefinedAtom::mergeAsTentative ) |
| 340 | continue; |
| 341 | assert(defAtom->scope() != DefinedAtom::scopeTranslationUnit); |
| 342 | // See if any shared library also has symbol which |
| 343 | // collides with the tentative definition. |
| 344 | // SymbolTable will warn if needed. |
| 345 | _inputFiles.searchLibraries(defAtom->name(), true, false, false, *this); |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | // get "main" atom for linkage unit |
| 350 | const Atom *Resolver::entryPoint() { |
| 351 | llvm::StringRef symbolName = _platform.entryPointName(); |
| 352 | if (symbolName != NULL) |
| 353 | return _symbolTable.findByName(symbolName); |
| 354 | |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | // give platform a chance to tweak the set of atoms |
| 359 | void Resolver::tweakAtoms() { |
| 360 | _platform.postResolveTweaks(_atoms); |
| 361 | } |
| 362 | |
| 363 | void Resolver::linkTimeOptimize() { |
| 364 | // FIX ME |
| 365 | } |
| 366 | |
| 367 | std::vector<const Atom *> &Resolver::resolve() { |
| 368 | this->initializeState(); |
| 369 | this->addInitialUndefines(); |
| 370 | this->buildInitialAtomList(); |
| 371 | this->resolveUndefines(); |
| 372 | this->updateReferences(); |
| 373 | this->deadStripOptimize(); |
| 374 | this->checkUndefines(false); |
| 375 | this->removeCoalescedAwayAtoms(); |
| 376 | this->checkDylibSymbolCollisions(); |
| 377 | this->linkTimeOptimize(); |
| 378 | this->tweakAtoms(); |
| 379 | return _atoms; |
| 380 | } |
| 381 | |
| 382 | } // namespace lld |