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

pub static disappears if only used from asm #13365

Closed
kmcallister opened this issue Apr 6, 2014 · 5 comments
Closed

pub static disappears if only used from asm #13365

kmcallister opened this issue Apr 6, 2014 · 5 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`)

Comments

@kmcallister
Copy link
Contributor

#[feature(asm)];

#[no_mangle]
pub static arr: [u8, ..16] = [0, ..16];

fn main() {
    unsafe {
        asm!("movups arr, %xmm0" ::: "xmm0");
    }
}
$ rustc -v
rustc 0.10-pre (68a4f7d 2014-02-24 12:42:02 -0800)
host: x86_64-unknown-linux-gnu

$ rustc -O foo.rs
error: linking with `cc` failed: exit code: 1
note: cc arguments: [...]
note: foo.o: In function `main::hcaa4d83fe49d03ddnaa::v0.0':
foo.rs:(.text+0x29): undefined reference to `arr'
collect2: error: ld returned 1 exit status

error: aborting due to previous error

Adding an unused constraint "r"(&arr) fixes it, as does passing &arr to test::black_box (which does basically that).

@steveklabnik
Copy link
Member

Traige: still true

@Stebalien
Copy link
Contributor

Still an issue. Updated example:

#![feature(asm)]

#[no_mangle]
pub static arr: [u8; 16] = [0; 16];

fn main() {
    unsafe {
        asm!("movups arr, %xmm0" ::: "xmm0");
    }
}

@brson
Copy link
Contributor

brson commented Mar 9, 2017

Error is different now:

rustc 1.17.0-nightly (b1e31766d 2017-03-03)
warning: static variable `arr` should have an upper case name such as `ARR`
 --> <anon>:4:1
  |
4 | pub static arr: [u8; 16] = [0; 16];
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(non_upper_case_globals)] on by default

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "./out.0.o" "-o" "./out" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-9a66b6a343d52844.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-6bc49e032a89c77d.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-a2a467c3ca3b6479.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-e54225ff8f33e08f.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-9d79f761aa668a33.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-2beb731af7a6faec.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ce7b9706e1719f27.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-4b74d6f2808677d3.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-95af4192ed69a1c8.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-cd0ca85e71f914ca.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0bf24067248742a8.rlib" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
  = note: /usr/bin/ld: ./out.0.o: relocation R_X86_64_32S against `arr' can not be used when making a shared object; recompile with -fPIC
          ./out.0.o: error adding symbols: Bad value
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

@nikomatsakis
Copy link
Contributor

The correct way to do this is to pass the array as a constrained variable (per @nagisa, who can provide more details) so that the compiler knows about the fact that arr is used (I imagine the fact that it is stripped is related to building a binary, not a library, as well). Closing.

@nagisa
Copy link
Member

nagisa commented Mar 9, 2017

Namely the code should be looking something like this:

asm!("movups $0, %xmm0" : "something"(arr) :: "xmm0")

instead.

compiler-errors pushed a commit to compiler-errors/rust that referenced this issue Oct 26, 2022
feat: add multiple getters mode in `generate_getter`

This commit adds two modes to generate_getter action.
First, the plain old working on single fields.
Second, working on a selected range of fields.

Should partially solve rust-lang#13246
If this gets approved will create a separate PR for setters version of the same

### Points to help in review:

- `generate_getter_from_record_info` contains code which is mostly taken from assist before refactor
- Same goes for `parse_record_fields`
- There are changes in other assists, as one of the methods in utils named `find_struct_impl` is changed, before it used to accept a single `fn_name`, now it takes a list of function names to check against. All old impls are updated to create a small list to pass their single element.

### Assumptions:

- If any of the fields have an implementation, the action will quit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`)
Projects
None yet
Development

No branches or pull requests

7 participants