Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possibly misaligned/aliased ivars? #25

Closed
sheffler opened this issue Nov 10, 2016 · 2 comments
Closed

possibly misaligned/aliased ivars? #25

sheffler opened this issue Nov 10, 2016 · 2 comments

Comments

@sheffler
Copy link

sheffler commented Nov 10, 2016

(not sure this is the right place to ask, but here goes)

Hello,

I am trying to use ObjC with ARC, libdispatch and blocks on Linux. I believe I am seeing a problem where ivars are referenced incorrectly, or are being aliased. I have tried to reduce the problem to a very small example.

Last year, using Ubuntu 12.04 and clang 3.4 I built and used ObjC and libobjc2 successfully. I am trying to recreate a similar working environment on Debian 8. I installed clang from 'apt-get'. It is version 3.5.

Here is the program that illustrates the problem. The arrays are there to illustrate that gnustep-base seems to be working. The ivars 'i' and 'j' are problematic.

// #import <Foundation/Foundation.h>

@interface Thing : NSObject
@property (readwrite) int i;
// @property int pad1;
// @property int pad2;
@property (readwrite) int j;
@property (readwrite) NSMutableArray * arr;
@end

@implementation Thing

- (id) init {
  if (self = [super init]) {
    _i = 5;
    _j = 17;
    _arr = [[NSMutableArray alloc] init];
    [_arr addObject:@"test1"];
    [_arr addObject:@"test2"];
  }
  return self;
}

@end

int main(int argc, char *argv[])
{

  NSLog(@"starting");

  NSMutableArray *thing = [[NSMutableArray alloc] init];
  [thing addObject:@"one"];
  [thing addObject:@"two"];
  [thing addObject:@"three"];
  NSLog(@"array:%@", thing);
  thing = [[NSMutableArray alloc] init];
  NSLog(@"array:%@", thing);

  Thing *t = [[Thing alloc] init];
  NSLog(@"Thing:%@", t);
  NSLog(@"i:%u", t.i);
  NSLog(@"j:%u", t.j);
  NSLog(@"arr:%@", t.arr);
}
  • On my Ubuntu 14.04 install it prints this:

2016-11-10 08:40:43.315 errorexample2[13183:13183] starting
2016-11-10 08:40:43.330 errorexample2[13183:13183] array:(one, two, three)
2016-11-10 08:40:43.332 errorexample2[13183:13183] array:()
2016-11-10 08:40:43.332 errorexample2[13183:13183] Thing:<Thing: 0x193d1c0>
2016-11-10 08:40:43.332 errorexample2[13183:13183] i:5
2016-11-10 08:40:43.332 errorexample2[13183:13183] j:17
2016-11-10 08:40:43.332 errorexample2[13183:13183] arr:(test1, test2)

  • On my Debian 8 install it prints this, the i and the j are aliased somehow, and they share the same value.

2016-11-10 08:38:46.121 errorexample2[26516:26516] starting
2016-11-10 08:38:46.122 errorexample2[26516:26516] array:(one, two, three)
2016-11-10 08:38:46.122 errorexample2[26516:26516] array:()
2016-11-10 08:38:46.122 errorexample2[26516:26516] Thing:<Thing: 0x1f1e070>
2016-11-10 08:38:46.123 errorexample2[26516:26516] i:17
2016-11-10 08:38:46.123 errorexample2[26516:26516] j:17
2016-11-10 08:38:46.123 errorexample2[26516:26516] arr:(test1, test2)

  • If I put in the padding properties, then things get even stranger.

2016-11-10 08:46:46.126 errorexample2[26553:26553] starting
2016-11-10 08:46:46.127 errorexample2[26553:26553] array:(one, two, three)
2016-11-10 08:46:46.127 errorexample2[26553:26553] array:()
2016-11-10 08:46:46.127 errorexample2[26553:26553] Thing:<Thing: 0x9d5070>
2016-11-10 08:46:46.128 errorexample2[26553:26553] i:10303216
2016-11-10 08:46:46.128 errorexample2[26553:26553] j:10303216
2016-11-10 08:46:46.128 errorexample2[26553:26553] arr:(test1, test2)

  • The recipe I've followed for building libobjc2 and libdispatch are as follows. I've repeated this a few times.
sudo apt -y install clang git ninja cmake libffi-dev libxml2-dev libgnutls28-dev libicu-dev libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev autoconf libtool libjpeg-dev libtiff-dev libffi-dev libcairo-dev libx11-dev libxt-dev libxft-dev libc++-dev

export CC=clang
export CXX=clang

# Checkout sources
git clone https://github.com/nickhutchinson/libdispatch.git
git clone https://github.com/gnustep/libobjc2.git
git clone https://github.com/gnustep/make
git clone https://github.com/gnustep/base.git
git clone https://github.com/gnustep/gui.git
git clone https://github.com/gnustep/back.git

cd libdispatch
mkdir build; cd build
make
sudo -E make install

cd libobjc2
cmake ../ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang -DCMAKE_ASM_COMPILER=clang -DTESTS=OFF
cmake --build .
sudo -E make install

export LDFLAGS=-L/usr/local/lib

cd make
./configure --enable-debug-by-default --with-layout=gnustep --enable-objc-nonfragile-abi
make
sudo -E make install
sudo ldconfig

cd base
make clean
./configure

export LD_LIBRARY_PATH=/usr/local/lib:/usr/GNUstep/Local/Library/Libraries

  • Now build the program

clang -g -o errorexample2 -x objective-c -fobjc-runtime=gnustep-1.8.1 -v -I/usr/local/include/objc -I/usr/GNUstep/Local/Library/Headers -f
objc-arc errorexample2.m Journal.m -L/usr/local/lib -L/usr/GNUstep/Local/Library/Libraries -lobjc -lgnustep-base -ldispatch

Any ideas or pointers are appreciated.

Thanks

@davidchisnall
Copy link
Member

This was a bug introduced recently. See: 25c7038.

If you're not using SSE or similar vectors, then 6b28593 should work correctly.

@sheffler
Copy link
Author

David -
thanks so much for your quick response. That was indeed the problem.

I began the investigation with a larger program that was exhibiting very mysterious behavior. Using the commit you showed, it seems to be working correctly now.

Much Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants