Invalid Segment Alignment when pushing to iTunesConnect

1,041 views
Skip to first unread message

pru...@gmail.com

unread,
Oct 22, 2017, 12:34:15 AM10/22/17
to golang-nuts
I'm getting the following error when trying to publish a go app to the itunes connect app store.

ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'bios.app/bios' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."

Please: Can anyone tell me what this error means and how to debug it?
I need help to determine if its just a matter of adding some external linker flags,
or if Apple has changed their ios binary requirements, or its something else entirely. 
I've created a test project at github.com/gazed/bios that can be used to recreate the error.

Background:
  • Similar to https://groups.google.com/forum/#!topic/golang-nuts/7TyYy5OIqD0
  • I've duplicated this error using the above github project, and also by submitting from xcode directly, and also by using a generated xcode project and the command line xcodebuild.
  • The above basic ios app works in developer mode. Its been run it on iphones 6S, 7, an ipad mini, and an ipad pro (great job on the go arm64 support!).
  • I have submitted an ios developer support ticket asking apple for more details regarding the apple error from the apple Application Loader tool. Apple replied:
"Thank you for contacting Apple Developer Technical Support (DTS). 
We’ve determined that your question should be addressed by the support channel for Go - the third-party resource you are using.  DTS supports developers using Apple-authored tools and frameworks only.".

Does the go development team have better access to apple support regarding details on apple errors? 
  • The google info on this error is sketchy. It is sometimes raised by those using ios framework tools and the problems are resolved by the framework developers, but I've not yet located a detailed description of the problem or how to debug it.
Thank you,
Paul

Elias Naur

unread,
Oct 22, 2017, 4:26:15 AM10/22/17
to golang-nuts
Hi Paul,

What version of Go, Xcode an macOS are you using? I'd like to help you debug the problem, but Xcode doesn't seem to allow me to run the validation of an archived build without a developer account.

 - elias

Elias Naur

unread,
Oct 22, 2017, 4:32:44 AM10/22/17
to golang-nuts
Another thing: Is the problem present in go tip (to become 1.10) as well? And finally, can you reproduce the problem with the simple golang.org/x/mobile/example/bind example?

 - elias

pru...@gmail.com

unread,
Oct 23, 2017, 7:24:19 AM10/23/17
to golang-nuts
go1.9.1 xcode 9.0.1 macOS 10.13.

pru...@gmail.com

unread,
Oct 23, 2017, 8:09:54 AM10/23/17
to golang-nuts
I reproduced the problem using the gomobile bind example with the following code changes.

diff --git a/cmd/gomobile/build_iosapp.go b/cmd/gomobile/build_iosapp.go

index 0b2a923..8480790 100644

--- a/cmd/gomobile/build_iosapp.go

+++ b/cmd/gomobile/build_iosapp.go

@@ -31,7 +31,7 @@ func goIOSBuild(pkg *build.Package) (map[string]bool, error) {

        infoplist := new(bytes.Buffer)

        if err := infoplistTmpl.Execute(infoplist, infoplistTmplData{

                // TODO: better bundle id.

-               BundleID: "org.golang.todo." + productName,

+               BundleID: "com.galvanizedlogic.bios",

                Name:     strings.Title(path.Base(pkg.ImportPath)),

        }); err != nil {

                return nil, err

@@ -97,7 +97,7 @@ func goIOSBuild(pkg *build.Package) (map[string]bool, error) {

        // Build and move the release build to the output directory.

        cmd = exec.Command(

                "xcrun", "xcodebuild",

-               "-configuration", "Release",

+               "-configuration", "Release", "-allowProvisioningUpdates",

                "-project", tmpdir+"/main.xcodeproj",

        )

        if err := runCmd(cmd); err != nil {

@@ -312,12 +312,14 @@ const projPbxproj = `// !$*UTF8*$!

         ORGANIZATIONNAME = Developer;

         TargetAttributes = {

           254BB83D1B1FD08900C56DE9 = {

-            CreatedOnToolsVersion = 6.3.1;

+            CreatedOnToolsVersion = 9.0;

+            DevelopmentTeam = 9829M3WGFP;

+            ProvisioningStyle = Automatic;

           };

         };

       };

       buildConfigurationList = 254BB8391B1FD08900C56DE9 /* Build configuration list for PBXProject "main" */;

-      compatibilityVersion = "Xcode 3.2";

+      compatibilityVersion = "Xcode 8.0";

       developmentRegion = English;

       hasScannedForEncodings = 0;

       knownRegions = (


Then repackaged bios.app and bios.ipa using the binary from the gomobile basic.app (avoids a bunch of invalid or missing icon errors). Validated that the app runs on an iphone 7. The upload ipa resulted in the following errors:


The "Invalid Bundle" is because gomobile builds a binary with both 32 and 64 bit executables.
I can't explain the PIE error. I did not get this error in the bios build even though I saw the "-nopie" when looking at a previous bios linker debug output.

Off to try tip now.

pru...@gmail.com

unread,
Oct 23, 2017, 8:12:45 AM10/23/17
to golang-nuts
Here is the error text in case the png doesn't display.
 
description length:93594

ERROR ITMS-90503: "Invalid Bundle. Apps that have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist must only contain the arm64 slice."

ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'bios.app/bios' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."

WARNING ITMS-90080: "The executable 'Payload/bios.app' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."

pru...@gmail.com

unread,
Oct 23, 2017, 8:44:40 AM10/23/17
to golang-nuts
Yes the error happens with tip. 

go version devel +006bc57095 Sun Oct 22 15:50:50 2017 +0000 darwin/amd64


On Sunday, October 22, 2017 at 4:32:44 AM UTC-4, Elias Naur wrote:

Elias Naur

unread,
Oct 23, 2017, 10:27:24 AM10/23/17
to pru...@gmail.com, golang-nuts
This seems like the "gomobile build" mode, not gomobile bind. There is a difference: build is for apps in 100% Go, while bind are for apps where a part is in Go. With gomobile bind, the Go part is built as a c-archive library and packaged in a framework. I know that you're interested in the gomobile build mode, but knowing whether gomobile bind apps have the same validation errors might help to debug the problem.

 - elias

pru...@gmail.com

unread,
Oct 23, 2017, 11:00:03 AM10/23/17
to golang-nuts
Trying bind this time.
Not able to build in Xcode with bind example. Xcode can't find the Hello module when following the instructions. Dropping the hello.framework into the ios folder seems to help but leads to the following linker error:

ld: '/Users/rust/code/src/golang.org/x/mobile/example/bind/ios/Hello.framework/Hello(000002.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)


Do the bind instructions from https://github.com/golang/go/wiki/Mobile work for you in Xcode 9? I accepted all Xcode fixes. Is it better to not do this?

Elias Naur

unread,
Oct 23, 2017, 11:03:51 AM10/23/17
to pru...@gmail.com, golang-nuts

To successfully build the bind example you need to disable bitcode (and import the framework as you did). Sorry.

- elias


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/DaCOnoSWvBw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pru...@gmail.com

unread,
Oct 23, 2017, 11:28:13 AM10/23/17
to golang-nuts
Ok thank you!. Bind does validate after setting ENABLE_BITCODE to NO in the build settings.

Elias Naur

unread,
Oct 23, 2017, 11:40:17 AM10/23/17
to pru...@gmail.com, golang-nuts
Great, thank you! I know very little about gomobile build, but I noticed that gomobile bind uses the -buildmode=c-archive flag to go build while gomobile build doesn't. Does the following (completely untested) patch make any difference:

diff --git a/cmd/gomobile/build_iosapp.go b/cmd/gomobile/build_iosapp.go
index 0b2a923..cf8da09 100644
--- a/cmd/gomobile/build_iosapp.go
+++ b/cmd/gomobile/build_iosapp.go
@@ -63,7 +63,7 @@ func goIOSBuild(pkg *build.Package) (map[string]bool, error) {
        ctx.BuildTags = append(ctx.BuildTags, "ios")
 
        armPath := filepath.Join(tmpdir, "arm")
-       if err := goBuild(src, darwinArmEnv, "-o="+armPath); err != nil {
+       if err := goBuild(src, darwinArmEnv, "-buildmode=c-archive", "-o="+armPath); err != nil {
                return nil, err
        }
        nmpkgs, err := extractPkgs(darwinArmNM, armPath)
@@ -72,7 +72,7 @@ func goIOSBuild(pkg *build.Package) (map[string]bool, error) {
        }
 
        arm64Path := filepath.Join(tmpdir, "arm64")
-       if err := goBuild(src, darwinArm64Env, "-o="+arm64Path); err != nil {
+       if err := goBuild(src, darwinArm64Env, "-buildmode=c-archive", "-o="+arm64Path); err != nil {
                return nil, err
        }
 
?

 - elias

pru...@gmail.com

unread,
Oct 23, 2017, 11:53:23 AM10/23/17
to golang-nuts
It does change things.

description length:88662
ERROR ITMS-90635: "Invalid Mach-O Format. The Mach-O in bundle "bios.app" isn’t consistent with the Mach-O in the main bundle. The main bundle Mach-O contains armv7(machine code) and armv7(machine code) and armv7(machine code) and armv7(machine code) and armv7(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code), while the nested bundle Mach-O contains armv7(machine code) and armv7(machine code) and armv7(machine code) and armv7(machine code) and armv7(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code) and arm64(machine code). Verify that all of the targets for a platform have a consistent value for the ENABLE_BITCODE build setting."
ERROR ITMS-90171: "Invalid Bundle Structure - The binary file 'bios.app/bios' is not permitted. Your app can’t contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at https://developer.apple.com/go/?id=bundle-structure for information on the iOS app bundle structure."
ERROR ITMS-90503: "Invalid Bundle. Apps that have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist must only contain the arm64 slice."
ERROR ITMS-90124: "The binary is invalid. The executable type "OBJECT" is not valid. Only "EXECUTE" is permitted."
ERROR ITMS-90125: "The binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's linker."
ERROR ITMS-90210: "Missing load commands. The executable at 'bios.app' does not have the necessary load commands. Try rebuilding the app with the latest Xcode version. If you are using third party development tools, contact the provider."
ERROR ITMS-90700: "Incorrect Platform. You included armv7 executable “bios.app/bios” in your iOS bundle. Only iOS executables can be included."
ERROR ITMS-90700: "Incorrect Platform. You included arm64 executable “bios.app/bios” in your iOS bundle. Only iOS executables can be included."

pru...@gmail.com

unread,
Oct 23, 2017, 11:54:41 AM10/23/17
to golang-nuts

On the off chance that it might be useful, here is some information on the bind example that validated:


~/Library/Developer/Xcode/Archives/2017-10-23/bind 2017-10-23, 11.24 AM.xcarchive/Products/Applications/bind.app: size -x -l -m bind 

Segment __PAGEZERO: 0x100000000 (vmaddr 0x0 fileoff 0)

Segment __TEXT: 0x94000 (vmaddr 0x100000000 fileoff 0)

Section __text: 0x8a3e0 (addr 0x1000077e8 offset 30696)

Section __stubs: 0x258 (addr 0x100091bc8 offset 596936)

Section __stub_helper: 0x270 (addr 0x100091e20 offset 597536)

Section __objc_methname: 0xd1a (addr 0x100092090 offset 598160)

Section __cstring: 0x412 (addr 0x100092daa offset 601514)

Section __objc_classname: 0x8f (addr 0x1000931bc offset 602556)

Section __objc_methtype: 0x8e7 (addr 0x10009324b offset 602699)

Section __gcc_except_tab: 0x3b8 (addr 0x100093b34 offset 604980)

Section __const: 0x8 (addr 0x100093ef0 offset 605936)

Section __unwind_info: 0x108 (addr 0x100093ef8 offset 605944)

total 0x8c812

Segment __DATA: 0xc4000 (vmaddr 0x100094000 fileoff 606208)

Section __got: 0x38 (addr 0x100094000 offset 606208)

Section __la_symbol_ptr: 0x190 (addr 0x100094038 offset 606264)

Section __mod_init_func: 0x18 (addr 0x1000941c8 offset 606664)

Section __cfstring: 0x1e0 (addr 0x1000941e0 offset 606688)

Section __objc_classlist: 0x38 (addr 0x1000943c0 offset 607168)

Section __objc_protolist: 0x28 (addr 0x1000943f8 offset 607224)

Section __objc_imageinfo: 0x8 (addr 0x100094420 offset 607264)

Section __objc_const: 0x1710 (addr 0x100094428 offset 607272)

Section __objc_selrefs: 0x130 (addr 0x100095b38 offset 613176)

Section __objc_classrefs: 0x60 (addr 0x100095c68 offset 613480)

Section __objc_superrefs: 0x30 (addr 0x100095cc8 offset 613576)

Section __objc_ivar: 0x2c (addr 0x100095cf8 offset 613624)

Section __objc_data: 0x230 (addr 0x100095d28 offset 613672)

Section __data: 0x5a40 (addr 0x100095f60 offset 614240)

Section __rodata: 0x3b7b4 (addr 0x10009b9a0 offset 637344)

Section __typelink: 0xa44 (addr 0x1000d7160 offset 880992)

Section __itablink: 0x70 (addr 0x1000d7ba8 offset 883624)

Section __gosymtab: 0x0 (addr 0x1000d7c18 offset 883736)

Section __gopclntab: 0x5156d (addr 0x1000d7c20 offset 883744)

Section __noptrdata: 0xcac4 (addr 0x1001291a0 offset 1216928)

Section __bss: 0x1c8a0 (addr 0x100135c80 offset 0)

Section __common: 0x10 (addr 0x100152520 offset 0)

Section __noptrbss: 0x22f8 (addr 0x100152540 offset 0)

total 0xc07d5

Segment __LINKEDIT: 0x10000 (vmaddr 0x100158000 fileoff 1277952)

total 0x100168000


Compared with the original bios binary that failed with “invalid segment alignment”


~/code/ghub/src/bios/admin/target/ios/Payload (master): size -x -l -m bios.app/bios 

Segment __PAGEZERO: 0x4000000 (vmaddr 0x0 fileoff 0)

Segment __TEXT: 0x144000 (vmaddr 0x4000000 fileoff 0)

Section __stubs: 0x204 (addr 0x40069b0 offset 27056)

Section __stub_helper: 0x21c (addr 0x4006bb4 offset 27572)

Section __text: 0x1381f8 (addr 0x4006dd0 offset 28112)

Section __const: 0x58 (addr 0x413efc8 offset 1306568)

Section __objc_methname: 0xda1 (addr 0x413f020 offset 1306656)

Section __objc_classname: 0x5a (addr 0x413fdc1 offset 1310145)

Section __objc_methtype: 0xa0a (addr 0x413fe1b offset 1310235)

Section __cstring: 0x3733 (addr 0x4140825 offset 1312805)

Section __unwind_info: 0xa4 (addr 0x4143f58 offset 1326936)

total 0x13d64c

Segment __DATA: 0x13c000 (vmaddr 0x4144000 fileoff 1327104)

Section __got: 0x20 (addr 0x4144000 offset 1327104)

Section __la_symbol_ptr: 0x158 (addr 0x4144020 offset 1327136)

Section __const: 0x80 (addr 0x4144178 offset 1327480)

Section __cfstring: 0x80 (addr 0x41441f8 offset 1327608)

Section __objc_classlist: 0x10 (addr 0x4144278 offset 1327736)

Section __objc_protolist: 0x20 (addr 0x4144288 offset 1327752)

Section __objc_imageinfo: 0x8 (addr 0x41442a8 offset 1327784)

Section __objc_const: 0xf98 (addr 0x41442b0 offset 1327792)

Section __objc_selrefs: 0xf0 (addr 0x4145248 offset 1331784)

Section __objc_classrefs: 0x28 (addr 0x4145338 offset 1332024)

Section __objc_superrefs: 0x8 (addr 0x4145360 offset 1332064)

Section __objc_ivar: 0x14 (addr 0x4145368 offset 1332072)

Section __objc_data: 0xa0 (addr 0x4145380 offset 1332096)

Section __rodata: 0x6f038 (addr 0x4145420 offset 1332256)

Section __typelink: 0x12f4 (addr 0x41b4460 offset 1786976)

Section __itablink: 0x2c8 (addr 0x41b5758 offset 1791832)

Section __gopclntab: 0x8f0fd (addr 0x41b5a20 offset 1792544)

Section __gosymtab: 0x0 (addr 0x4244b1d offset 2378525)

Section __noptrdata: 0x109a0 (addr 0x4244b20 offset 2378528)

Section __data: 0x72a0 (addr 0x42554c0 offset 2446528)

Section __bss: 0x1d1f8 (addr 0x425c760 offset 0)

Section __noptrbss: 0x2338 (addr 0x4279960 offset 0)

Section __common: 0x1638 (addr 0x427bc98 offset 0)

total 0x1392b5

Segment __LINKEDIT: 0x78000 (vmaddr 0x4280000 fileoff 2490368)

total 0x42f8000

pru...@gmail.com

unread,
Oct 23, 2017, 12:24:05 PM10/23/17
to golang-nuts
Making the following change fixes the original problem and allows my ios apps to be uploaded:

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index bd3abbba0a..45642e8ad7 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1105,7 +1105,7 @@ func (ctxt *Link) hostlink() {
        switch ctxt.BuildMode {
        case BuildModeExe:
                if ctxt.HeadType == objabi.Hdarwin {
-                       argv = append(argv, "-Wl,-pagezero_size,4000000")
+                       argv = append(argv, "-Wl,-pagezero_size,100000000")
                }
        case BuildModePIE:
                // ELF.

Elias Naur

unread,
Oct 23, 2017, 12:31:44 PM10/23/17
to golang-nuts
Fantastic! Would you like to send this patch as a change list?

 - elias

pru...@gmail.com

unread,
Oct 23, 2017, 12:56:00 PM10/23/17
to golang-nuts
Maybe? I would appreciate your help in this matter. What is the quickest way to confirm that the change makes sense, doesn't break previous ios related stuff, and get it into the next go release? I don't want to hold things up as I google "change list" with various combinations of "golang", "git" and "submit go patch".

I had thought about raising a golang issue as the next step. Would this make sense?

Elias Naur

unread,
Oct 23, 2017, 1:01:59 PM10/23/17
to pru...@gmail.com, golang-nuts
There's a guide at https://golang.org/doc/contribute.html to help submitting a change to the code review tool used by Go. Raising an issue is great, but an actual change is the fastest way forward in this case (iOS is a fringe OS in Go). With a CL, the change will be reviewed by someone who knows the low level linker flags such as pagezero_size.

 - elias

pru...@gmail.com

unread,
Oct 23, 2017, 1:26:00 PM10/23/17
to golang-nuts
Going over the contribution guide now.
Tracking with: https://github.com/golang/go/issues/22402
Thank you for your help!
Reply all
Reply to author
Forward
0 new messages