]>
git.saurik.com Git - apple/ld64.git/blob - src/ld/passes/dylibs.cpp
   1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*- 
   3  * Copyright (c) 2010 Apple Inc. All rights reserved. 
   5  * @APPLE_LICENSE_HEADER_START@ 
   7  * This file contains Original Code and/or Modifications of Original Code 
   8  * as defined in and that are subject to the Apple Public Source License 
   9  * Version 2.0 (the 'License'). You may not use this file except in 
  10  * compliance with the License. Please obtain a copy of the License at 
  11  * http://www.opensource.apple.com/apsl/ and read it before using this 
  14  * The Original Code and all software distributed under the License are 
  15  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  16  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  17  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  18  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  19  * Please see the License for the specific language governing rights and 
  20  * limitations under the License. 
  22  * @APPLE_LICENSE_HEADER_END@ 
  30 #include <mach/machine.h> 
  45         bool operator()(ld::dylib::File
* dylib
) const { 
  46                 return dylib
->willRemoved(); 
  51 void doPass(const Options
& opts
, ld::Internal
& state
) 
  53 //      const bool log = false; 
  55         // only optimize dylibs in final linked images 
  56         if ( opts
.outputKind() == Options::kObjectFile 
) 
  59         // clear "willRemoved" bit on all dylibs 
  60         for (std::vector
<ld::dylib::File
*>::iterator it 
= state
.dylibs
.begin(); it 
!= state
.dylibs
.end(); ++it
) { 
  61                 ld::dylib::File
* aDylib 
= *it
; 
  62                 aDylib
->setWillBeRemoved(false); 
  64         for (std::vector
<ld::dylib::File
*>::iterator it 
= state
.dylibs
.begin(); it 
!= state
.dylibs
.end(); ++it
) { 
  65                 ld::dylib::File
* aDylib 
= *it
; 
  66                 // set "willRemoved" bit on implicit dylibs that did not provide any exports 
  67                 if ( aDylib
->implicitlyLinked() && !aDylib
->explicitlyLinked() && !aDylib
->providedExportAtom() ) 
  68                         aDylib
->setWillBeRemoved(true); 
  69                 // set "willRemoved" bit on dead strippable explicit dylibs that did not provide any exports 
  70                 if ( aDylib
->explicitlyLinked() && aDylib
->deadStrippable() && !aDylib
->providedExportAtom() ) 
  71                         aDylib
->setWillBeRemoved(true); 
  72                 // set "willRemoved" bit on any unused explicit when -dead_strip_dylibs is used 
  73                 if ( opts
.deadStripDylibs() && !aDylib
->providedExportAtom() ) 
  74                         aDylib
->setWillBeRemoved(true); 
  78         // remove unused dylibs 
  79         state
.dylibs
.erase(std::remove_if(state
.dylibs
.begin(), state
.dylibs
.end(), WillBeUsed()), state
.dylibs
.end());