[llvm-commits] patch: pick direct or indirect strings in DWARF

Nick Lewycky nlewycky at google.com
Mon Oct 24 19:27:47 PDT 2011


DWARF allows string to be specified in one of two ways, either by writing
them literally (DW_FORM_string) or by including a pointer into the
.debug_str section and putting the NUL-terminated string there.

The attached patch removes the Form argument from CompileUnit::AddString and
changes addString to emit either a DIEString or a DIELabel depending on how
long the string is. If the string would fit in 4 bytes in the direct
encoding, do that. Otherwise, hoist it out into .debug_str so that it can be
interned.

This is a major issue on linux where the linker does not turn direct strings
into indirect strings, but does merge the string tables. On Darwin, the
linker will turn direct strings into indirect strings as needed. However,
this change should probably be enabled on all platforms as it generally
makes .o files smaller.

Please review! The one thing I don't like about this patch is that we emit
the bytes (via .ascii) and then emit the NUL (via. ".zero 1"). The
alternatives I see are either to create a copy of the string, or to create a
new emitBytesWithNUL API in MCStreamer.

Nick

PS. If this patch doesn't work on Darwin out-of-the-box, please try one
thing for me: comment out the change to DIELabel::SizeOf (adding a case for
DW_FORM_strp), and let me know whether that fixes things.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111024/9ba9999e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dwarf-indirect-string-1.patch
Type: text/x-patch
Size: 11514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111024/9ba9999e/attachment.bin>


More information about the llvm-commits mailing list