summaryrefslogtreecommitdiffstats
path: root/lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-11-07 02:54:52 +0000
committerRui Ueyama <ruiu@google.com>2014-11-07 02:54:52 +0000
commita81cb0594b34add75060ac9371bf93995158621e (patch)
tree72d9ab4ed4f98aba16a426ff8cd5b0d9f94158cd /lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
parent72001cf287fac7b37009cf0a94065cd06831718d (diff)
downloadbcm5719-llvm-a81cb0594b34add75060ac9371bf93995158621e.tar.gz
bcm5719-llvm-a81cb0594b34add75060ac9371bf93995158621e.zip
Fix Mach-O unit tests breakage on Windows
Mach-O normalized file reader assumes that the entire file is aligned to a large boundary. If the in-memory file is not aligned properly, it will abort with an assertion failure in read32/read64. This patch forces the in-memory file for the unit test to be aligned at 64-byte boundary. I found these tests are failing on Windows, but theoretically they could fail on other platform. llvm-svn: 221508
Diffstat (limited to 'lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp')
-rw-r--r--lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp b/lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
index b49cc1fd697..22ed3f15b3e 100644
--- a/lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
+++ b/lld/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
@@ -31,9 +31,17 @@ fromBinary(const uint8_t bytes[], unsigned length, StringRef archStr) {
return std::move(*r);
}
+// The Mach-O object reader uses functions such as read32 or read64
+// which don't allow unaligned access. Our in-memory object file
+// needs to be aligned to a larger boundary than uint8_t's.
+#if _MSC_VER
+#define FILEBYTES __declspec(align(64)) const uint8_t fileBytes[]
+#else
+#define FILEBYTES const uint8_t fileBytes[] __attribute__((aligned(64)))
+#endif
TEST(BinaryReaderTest, empty_obj_x86_64) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xcf, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x01,
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00,
@@ -69,7 +77,7 @@ TEST(BinaryReaderTest, empty_obj_x86_64) {
TEST(BinaryReaderTest, empty_obj_x86) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xce, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
@@ -101,7 +109,7 @@ TEST(BinaryReaderTest, empty_obj_x86) {
TEST(BinaryReaderTest, empty_obj_ppc) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xfe, 0xed, 0xfa, 0xce, 0x00, 0x00, 0x00, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7c,
@@ -133,7 +141,7 @@ TEST(BinaryReaderTest, empty_obj_ppc) {
TEST(BinaryReaderTest, empty_obj_armv7) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xce, 0xfa, 0xed, 0xfe, 0x0c, 0x00, 0x00, 0x00,
0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
@@ -164,7 +172,7 @@ TEST(BinaryReaderTest, empty_obj_armv7) {
}
TEST(BinaryReaderTest, empty_obj_x86_64_arm7) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
#include "empty_obj_x86_armv7.txt"
};
std::unique_ptr<NormalizedFile> f =
@@ -187,7 +195,7 @@ TEST(BinaryReaderTest, empty_obj_x86_64_arm7) {
}
TEST(BinaryReaderTest, hello_obj_x86_64) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xCF, 0xFA, 0xED, 0xFE, 0x07, 0x00, 0x00, 0x01,
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00,
@@ -320,7 +328,7 @@ TEST(BinaryReaderTest, hello_obj_x86_64) {
TEST(BinaryReaderTest, hello_obj_x86) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xCE, 0xFA, 0xED, 0xFE, 0x07, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00,
@@ -452,7 +460,7 @@ TEST(BinaryReaderTest, hello_obj_x86) {
TEST(BinaryReaderTest, hello_obj_armv7) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xCE, 0xFA, 0xED, 0xFE, 0x0C, 0x00, 0x00, 0x00,
0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00,
@@ -594,7 +602,7 @@ TEST(BinaryReaderTest, hello_obj_armv7) {
TEST(BinaryReaderTest, hello_obj_ppc) {
- const uint8_t fileBytes[] = {
+ FILEBYTES = {
0xFE, 0xED, 0xFA, 0xCE, 0x00, 0x00, 0x00, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x28,
@@ -738,4 +746,3 @@ TEST(BinaryReaderTest, hello_obj_ppc) {
writeBinary(*f, "/tmp/foo.o");
}
-
OpenPOWER on IntegriCloud