<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><catching up on old mail></div><div><br class="webkit-block-placeholder"></div><div>On Feb 27, 2008, at 2:22 PM, Nick Kledzik wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite"><blockquote type="cite"><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">+#include <fstream></span></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+#include <unistd.h><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+#include <stdlib.h><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+#include <fcntl.h><br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">For standard c++ headers like stdlib, please use <cstdlib>.  Is it possible to avoid unistd.h/fcntl.h with the llvm/System/Path.h or MemoryBuffer.h stuff?  MemoryBuffer.h is an efficient way to read an entire file in off the disk.<br></blockquote>The issue is that lto_codegen_compile() returns a malloc'ed block which the client frees when done.  I don't see a way to use MemoryBuffer that allows me to transfer ownership of the underlying buffer away and then delete the buffer.  Also if looks like MemoryBuffer::getFile() mmaps the file instead of using malloc() so, the client then can't free() it.   What I've done is change the commensts for to_codegen_compile() to say that the returned buffer is owned by the lto_codegen_t object and is freed with it is disposed.  Then I got rid of the malloc/open/read and used MemoryBuffer::getFile().</span></blockquote><div><br class="webkit-block-placeholder"></div>Nice</div><div><br class="webkit-block-placeholder"></div><div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">+    bool                writeMergedModules(const char* path, std::string& errMsg);<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This goes over 80 columns.<br></blockquote>Fixed (I just threw that one in to see if the rumors were true, and the are ;-)</span></blockquote><div><br class="webkit-block-placeholder"></div><div>Hehe, so you're just toying with me huh? ;-)</div><div><br class="webkit-block-placeholder"></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite">Please use RAII and early exits to simplify the code.  A useful thing for this is llvm/ADT/OwningPtr.h.  You should be able to do something like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> OwningPtr<MemoryBuffer> buffer = MemoryBuffer::getMemBuffer...<br></blockquote><blockquote type="cite"><br></blockquote></span></blockquote><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">Hey!  OwningPtr<> is not in the Xcode project.  That is how I've been search llvm sources.</span></blockquote><div><br class="webkit-block-placeholder"></div><div>Yeah, unfortunately, the xcode project doesn't get much love :(</div><div><br class="webkit-block-placeholder"></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">I reworked this to use OwningPtr<> and factored out the target matching code, and yes it is all much smaller now.  Cool!</span></blockquote><div><br class="webkit-block-placeholder"></div>Great!</div><div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite"><blockquote type="cite"><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">Wow, that is a hack.  :)  We should really fix this at the LLVM IR level, can you please file a radar that demonstrates how not distinguishing between these two cases cause a problem?</span></blockquote></blockquote>We already have <<a href="rdar://problem/5684011">rdar://problem/5684011</a>> that Dale wrote up.</span></blockquote><div><br class="webkit-block-placeholder"></div>Ok</div><div><br class="webkit-block-placeholder"></div><div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite"><blockquote type="cite">+        // Use mangler to add GlobalPrefix to names to match linker names.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+        Mangler mangler(*_module, _target->getTargetAsmInfo()->getGlobalPrefix());<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">There is one other aspect of configuration for the mangler: On darwin at least you have to call manger.setUseQuotes(true);<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This tells it that it is ok to make some symbols use double quotes (e.g. those with a space in them like objc methods) instead of mangling the space.  I don't know if we can currently get this from TargetAsmInfo.h, but I think we should be able to.  Dale or Evan can help with this part.</blockquote></span></blockquote><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; ">I don't think this is applicable at this level.  You need double quotes around ObjC method names in the generated assembly source file because the otherwise the assembler can't parse the label name.  The linker and LTO use raw const char* strings which can have embedded spaces.</span></blockquote><div><br class="webkit-block-placeholder"></div>Ok, but I'm concerned about the mangler mangling strings in other ways.  If you have a name that contains a space, for example, when "quotes" are supported, the mangler will leave the space but wrap the name with quotes.  When quotes are not available, the mangler will replace the space with something gross.  Basically not setting quotes will get you a different string than enabling quotes and then removing the quotes from the name.</div><div><br class="webkit-block-placeholder"></div><div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><blockquote type="cite"><blockquote type="cite">+// holds most recent error string<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+// *** not thread safe ***<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+static std::string sLastErrorString;<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This also has a static ctor, which we try to avoid when possible (yes, we don't avoid very well, but we still try :).  Is there another way to do this?<br></blockquote>Even without it, there is still a static ctor in lto.o.  Something to do with ManglerLinkVar and IncludeFile().<br>Given that there are a couple hundred ctors in the libLTO.dylib, I'm not to worried about this one.<br></span></blockquote></div><br><div>Ok.</div><div><br class="webkit-block-placeholder"></div><div>Thanks Nick!</div><div><br class="webkit-block-placeholder"></div><div>-Chris</div></body></html>