Search code examples
iosllvmtheos

What's the meaning of LDFLAGS: -Wl,-segalign,4000


So I came across a cydia update notes:

0.9.6010 fixes the 32-bit armv7 slice, which was keeping extensions from loading into Cydia. (Note that, additionally, all 32-bit binaries, in particular extensions, must be recompiled using -WI,-segalign,4000 for iOS 9 due to a change made by Apple. Extensions that have not been recompiled might “get lucky” and work, but they will usually either fail or even crash.)

I want to ask here what's the meaning of each flag -WI, -segalign,4000, especially is it -WI or -Wl? Do we still need it if only for arm64 devices?


Solution

  • Here's the flag bisected into indvidual parts:

    • -Wl From clang docs, this is a command line flag that allows you to pass arguments directly to the linker (clang is a driver that calls the linker, -Wl means that the following coma separated arguments are forwarded the linker rather than being consumed by the compiler)
    • segalign From Mach linker docs, this specifies the segment alignment (segment as in binary file segment, see Wikipedia). In this case, every segment has to be aligned to 16384 bytes (or, 0x4000 in hex).
    • 4000 is the value of the alignment (it's part of the -segalign flag.

    Do we still need it if only for arm64 devices?

    You are referring to an Armv7 specific fix/notes. Unless arm64 is mentioned in the notes too, I imagine that it's safe to assume that that flag is not required for arm64. That's just a guess though.