diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-20 20:33:18 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-20 20:33:18 +0000 |
commit | 68aa3e10547409a98d865dc56fec9af8243a192f (patch) | |
tree | aead80ac22a971e91dab34c1c5afaabff66447cd /lib/CodeGen/CodeGenModule.cpp | |
parent | c50bf3d128af641f9249f7d1dc37e42b9fd31b81 (diff) | |
download | clang-68aa3e10547409a98d865dc56fec9af8243a192f.tar.gz clang-68aa3e10547409a98d865dc56fec9af8243a192f.tar.bz2 clang-68aa3e10547409a98d865dc56fec9af8243a192f.tar.xz |
Give explicit sections for string constants used in NSStrings.
Without them they can be merged with non unnamed_addr constants during LTO.
The resulting constant is not unnamed_addr and goes in a different section,
which causes ld64 to crash.
A testcase that would crash before:
* file1.mm:
void g(id notification) {
[notification valueForKey:@"name"];
}
* file2.cpp:
extern const char js_name_str[] = "name";
* file3.cpp
extern bool JS_GetProperty(const char *name);
extern const char js_name_str[];
bool js_ReportUncaughtException() { JS_GetProperty(js_name_str); }
run
clang file1.mm -o file1.o -c -w -emit-llvm
clang file2.cpp -o file2.o -c -w -emit-llvm
clang file3.cpp -o file3.o -c -w
ld -dylib -o XUL file1.o file2.o file3.o -undefined dynamic_lookup.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199688 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 88e6e66f9c..12edab7cd6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2396,12 +2396,17 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { GV->setUnnamedAddr(true); // Don't enforce the target's minimum global alignment, since the only use // of the string is via this class initializer. + // FIXME: We set the section explicitly to avoid a bug in ld64 224.1. Without + // it LLVM can merge the string with a non unnamed_addr one during LTO. Doing + // that changes the section it ends in, which surprises ld64. if (isUTF16) { CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy); GV->setAlignment(Align.getQuantity()); + GV->setSection("__TEXT,__ustring"); } else { CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy); GV->setAlignment(Align.getQuantity()); + GV->setSection("__TEXT,__cstring,cstring_literals"); } // String. |