News for hackers. Stuff that matters.
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by saagarjha on Wednesday May 06, 2020 @07:57PM (#23097957)
(For the iOS engineers reading along: please don't put network calls in +load, or __attribute__((constructor)), or a C++ static variable, or whatever other clever way you think you can get code execution before main.)
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by red_admiral on Thursday May 07, 2020 @04:21AM (#23100897)
For the iOS developers reading along: please ban this behaviour in a future version?
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by ynx on Friday May 08, 2020 @01:01AM (#23111558)
This is akin to banning any application that calls 'malloc' and 'free'.

To do ban static constructors they'd have to literally ban anything that links the C++ runtime, which is almost literally everything on your system.

Not possible.

Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by red_admiral on Friday May 08, 2020 @09:30AM (#23114650)
Not 'ban static constructors', sorry if I wasn't clear. Ban network I/O before main() has started.
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by kccqzy on Wednesday May 06, 2020 @09:57PM (#23098818)
Not just network calls, but also the file system, or basically anything nontrivial.

C++ static variables can now be annotated with constinit to resolve issues like this: https://en.cppreference.com/w/cpp/language/constinit It basically asks the compiler to enforce that constructor calls can only do trivial things.

Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by favorited on Wednesday May 06, 2020 @08:21PM (#23098158)
Even better: don't override +load or use static constructors!
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by saagarjha on Wednesday May 06, 2020 @08:30PM (#23098227)
Eh, I wouldn't go that far; they do have their uses. But for a SDK author, it pays to be excessively cautious when putting things on the application startup path. (Something which the Facebook is well aware of, as the dyld session is always full of their company's engineers, and the architecture of their app shows that put effort into meeting launch deadlines…)
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by favorited on Thursday May 07, 2020 @03:28AM (#23100610)
Every bad thing has its uses. If an SDK author wants to be a responsible participant in the app's startup path, it will defer its own setup to the app.

`__attribute__((constructor))` is most obviously a hack – like any great hack, it is useful enough to be implemented everywhere, but it will never be standardized because everyone acknowledges that it sucks. I used to use it! But it is extremely limited in its usefulness, and there are always better solutions to the problem.

Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by rohansuri on Thursday May 07, 2020 @02:18AM (#23100239)
(non C++ developer here) What is the +load being referred?
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by zerocrates on Thursday May 07, 2020 @02:39AM (#23100344)
It's Objective-C being referred to here: the "+" prefix indicates a class method.

Any class can implement +load and the runtime will call the method upon loading the class (note, this doesn't require using it at all).

https://developer.apple.com/documentation/objectivec/nsobjec...

Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by vvG94KbDUtRa on Wednesday May 06, 2020 @08:30PM (#23098230)
Spoken like someone who has never tried to optimize startup time. If network is your blocker, you need to do it as soon as possible
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by saagarjha on Wednesday May 06, 2020 @08:37PM (#23098280)
Putting more code in a constructor is almost never advised. I would expect that whatever connection the Facebook SDK is making is not a blocker for application launch. (If you have more insight on why this code must unconditionally run this early, I would be glad to hear it.)
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by munchbunny on Thursday May 07, 2020 @02:14AM (#23100219)
The gain from trying to eke out a millisecond by executing network or filesystem I/O code before main() is extremely marginal compared to the can of worms opened by doing that.
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by jfkebwjsbx on Wednesday May 06, 2020 @08:41PM (#23098307)
Running code before main has nothing to do with performance.
Re:Facebook iOS SDK Remotely Crashing Spotify, TikTok, Pinte... by unilynx on Thursday May 07, 2020 @05:32AM (#23101229)
It surely does, performance is more about just raw CPU. Prefetching data (even a DNS query) reduces the latency the user perceives.

The web similarly added the various <link rel=preload, dns-prefetch> tags, so things can be connected and fetched before the JS/CSS code is ready