Skip to content

Commit

Permalink
rustc: Pass --enable-long-section-names to gcc
Browse files Browse the repository at this point in the history
This was quite a curious bug on windows, and the details can be found in the
comment I added to src/librustc/back/link.rs
  • Loading branch information
alexcrichton committed Apr 6, 2014
1 parent 0459ee7 commit 38f7a1b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
#![allow(missing_doc)]
#![allow(uppercase_variables)]

#![feature(link_args)] // NOTE: remove after stage0

#[cfg(test)] extern crate std;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate native;
Expand Down Expand Up @@ -197,6 +199,11 @@ pub use funcs::posix88::unistd::{rmdir, unlink, write};
#[link(name = "m")]
extern {}

// NOTE: remove this after a stage0 snap
#[cfg(stage0, windows)]
#[link_args = "-Wl,--enable-long-section-names"]
extern {}

/// A wrapper for a nullable pointer. Don't use this except for interacting
/// with libc. Basically Option, but without the dependance on libstd.
// If/when libprim happens, this can be removed in favor of that
Expand Down
27 changes: 27 additions & 0 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,33 @@ fn link_args(sess: &Session,
// DWARF stack unwinding will not work.
// This behavior may be overridden by --link-args "-static-libgcc"
args.push(~"-shared-libgcc");

// And here, we see obscure linker flags #45. On windows, it has been
// found to be necessary to have this flag to compile liblibc.
//
// First a bit of background. On Windows, the file format is not ELF,
// but COFF (at least according to LLVM). COFF doesn't officially allow
// for section names over 8 characters, apparently. Our metadata
// section, ".note.rustc", you'll note is over 8 characters.
//
// On more recent versions of gcc on mingw, apparently the section name
// is *not* truncated, but rather stored elsewhere in a separate lookup
// table. On older versions of gcc, they apparently always truncated the
// section names (at least in some cases). Truncating the section name
// actually creates "invalid" objects [1] [2], but only for some
// introspection tools, not in terms of whether it can be loaded.
//
// Long story shory, passing this flag forces the linker to *not*
// truncate section names (so we can find the metadata section after
// it's compiled). The real kicker is that rust compiled just fine on
// windows for quite a long time *without* this flag, so I have no idea
// why it suddenly started failing for liblibc. Regardless, we
// definitely don't want section name truncation, so we're keeping this
// flag for windows.
//
// [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
// [2] - https://code.google.com/p/go/issues/detail?id=2139
args.push(~"-Wl,--enable-long-section-names");
}

if sess.targ_cfg.os == abi::OsAndroid {
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make/lto-smoke-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ifneq ($(shell uname),Darwin)
EXTRAFLAGS := -lm -lrt -ldl -lpthread
endif

# Apparently older versions of GCC segfault if -g is passed...
CC := $(CC:-g=)

all:
$(RUSTC) foo.rs -Z lto
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/lto-smoke-c/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[crate_type = "staticlib"];
#![crate_type = "staticlib"]

#[no_mangle]
pub extern "C" fn foo() {}

20 comments on commit 38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, me
at alexcrichton@38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libc = 38f7a1b into auto

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libc = 38f7a1b merged ok, testing candidate = cfdbfda2

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, me
at alexcrichton@38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libc = 38f7a1b into auto

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libc = 38f7a1b merged ok, testing candidate = 588f941f

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, me
at alexcrichton@38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libc = 38f7a1b into auto

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libc = 38f7a1b merged ok, testing candidate = 3181a774

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, me
at alexcrichton@38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libc = 38f7a1b into auto

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libc = 38f7a1b merged ok, testing candidate = c98df218

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, me
at alexcrichton@38f7a1b

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/libc = 38f7a1b into auto

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/libc = 38f7a1b merged ok, testing candidate = f1f5056

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 38f7a1b Apr 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = f1f5056

Please sign in to comment.