Skip to content

rustc places an absolute address into a jump table for imported functions instead of a relative one #23216

Description

@CtrlZvi

This code:

#![feature(libc, unicode)]
extern crate libc;
extern crate unicode;

#[cfg(target_family = "windows")]
#[allow(non_snake_case)]
#[link(name = "vccorlib")]
extern "C" {
    #[link_name = "?GetCmdArguments@Details@Platform@@YAPEAPEA_WPEAH@Z"]
    pub fn GetCmdArguments(argc : *mut libc::c_int) -> *const *const libc::wchar_t;
}

#[unstable]
pub fn get_command_arguments(argc : libc::c_int) -> (*const *const libc::wchar_t, libc::c_int) {
    let mut argc = argc;
    ( unsafe { GetCmdArguments(&mut argc) }, argc)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_command_arguments() {
        get_command_arguments(0);
    }
}
rustc minimumrepro.rs --crate-name minimumrepro --crate-type lib -g --test --emit=dep-info,link -L "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib/store/amd64"

should produce the following code (provided as a disassembly snippet):

...
000000000052CF18  jmp         qword ptr [6147d0h]  
000000000052CF1E  nop  
000000000052CF1F  nop  
...

But it instead produces the following code

...
000000000052CF18  jmp         qword ptr [0B416EEh]  
000000000052CF1E  nop  
000000000052CF1F  nop  
...

The difference is in the first entry of the jump table, which is the entry for the function explicitly mentioned in the source code. The incorrect value is caused by an absolute offset being written into the binary instead of a relative one. 0x52cf1e + 0x6147d0 = 0xb416ee.

Meta

rustc --version --verbose:
rustc 1.0.0-nightly (2fc8b1e 2015-03-07) (built 2015-03-08)
binary: rustc
commit-hash: 2fc8b1e
commit-date: 2015-03-07
build-date: 2015-03-08
host: x86_64-pc-windows-gnu
release: 1.0.0-nightly

Backtrace:

N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-linkageArea: linking into static, shared libraries and binariesO-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions