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

__imp___xxx is found in rust lib, however __imp__xxx is wanted when compiling my rust project #60866

Closed
chandde opened this issue May 15, 2019 · 8 comments

Comments

@chandde
Copy link
Contributor

chandde commented May 15, 2019

Hello

I was trying to build rustc target for thumbv7a-pc-windows-msvc locally, with a patch to compiler-builtins from this PR rust-lang/compiler-builtins#293, also hacked panic_unwind for thumbv7a similar to what we have for aarch64, https://github.com/rust-lang/rust/blob/master/src/libtest/lib.rs#L45, and I was able to build the target thumbv7a-pc-windows-msvc successfully, with below build command,
c:\python27\python.exe x.py build --host x86_64-pc-windows-msvc --build x86_64-pc-windows-msvc --target thumbv7a-pc-windows-msvc --verbose

After the build I tried to use my private tool chain to build some other rust projects, e.g. iotedged-eventlog-messages, I received below build errors. I used a few different ways to merge artifacts from different stages

  1. use only stage1, does not even recognize thumbv7a
  2. copy stage2 over stage1, overwrite anything with same name that exists in stage1, I got below error
  3. the other way of bind's glue function should tail-call its target  #2, same error.
   Compiling iotedged-eventlog-messages v0.1.0 (D:\git\iotedge\edgelet\iotedged-eventlog-messages)
     Running `rustc --edition=2018 --crate-name iotedged_eventlog_messages iotedged-eventlog-messages\src\lib.rs --color always --crate-type cdylib --emit=dep-info,link -C opt-level=3 -C metadata=7b3a2d69b8dc278f --out-dir D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps --target thumbv7a-pc-windows-msvc -L dependency=D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps -L dependency=D:\git\iotedge\edgelet\target\release\deps -L all=D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\build\iotedged-eventlog-messages-7acc25993b93c4f2\out -l event_messages.res`
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\arm\\link.exe" "/NOLOGO" "/NXCOMPAT" "/OPT:NOLBR" "/LIBPATH:E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib" "D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\deps\\iotedged_eventlog_messages.iotedged_eventlog_messages.cr16zstb-cgu.0.rcgu.o" "/OUT:D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\deps\\iotedged_eventlog_messages.dll" "/DEF:C:\\Users\\chandde\\AppData\\Local\\Temp\\rustcLXLSml\\lib.def" "D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\deps\\iotedged_eventlog_messages.28a4ogesychbfxh1.rcgu.o" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\deps" "/LIBPATH:D:\\git\\iotedge\\edgelet\\target\\release\\deps" "/LIBPATH:D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\build\\iotedged-eventlog-messages-7acc25993b93c4f2\\out" "/LIBPATH:E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib" "event_messages.res.lib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libstd-67da064321eabc9f.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libpanic_abort-9adb8660ecc33a7a.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\librustc_demangle-df85f75ef53673fc.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libhashbrown-9bd3a3fbf8f3ed5e.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-edfd9642cc94109d.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libunwind-3ac22205e93ddd40.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\liblibc-1287bf1fe4191b4b.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\liballoc-822d54421becb1c7.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\librustc_std_workspace_core-d51e26897332c0c9.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libcore-1fdb51d4e6dfea00.rlib" "E:\\rustc\\mixed2\\lib\\rustlib\\thumbv7a-pc-windows-msvc\\lib\\libcompiler_builtins-32eb33d96a637274.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib" "/DLL" "/IMPLIB:D:\\git\\iotedge\\edgelet\\target\\thumbv7a-pc-windows-msvc\\release\\deps\\iotedged_eventlog_messages.dll.lib"
  = note:    Creating library D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps\iotedged_eventlog_messages.dll.lib and object D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps\iotedged_eventlog_messages.dll.exp
          libstd-67da064321eabc9f.rlib(std-67da064321eabc9f.std.38mh430v-cgu.5.rcgu.o) : error LNK2019: unresolved external symbol __imp__ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E referenced in function _ZN3std3sys7windows7process7Command3new17hc990fb56302414eaE
          libstd-67da064321eabc9f.rlib(std-67da064321eabc9f.std.38mh430v-cgu.12.rcgu.o) : error LNK2001: unresolved external symbol __imp__ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E
          libstd-67da064321eabc9f.rlib(std-67da064321eabc9f.std.38mh430v-cgu.14.rcgu.o) : error LNK2001: unresolved external symbol __imp__ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E
          libstd-67da064321eabc9f.rlib(std-67da064321eabc9f.std.38mh430v-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol __imp__ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E
          D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps\iotedged_eventlog_messages.dll : fatal error LNK1120: 1 unresolved externals


error: aborting due to previous error

error: Could not compile `iotedged-eventlog-messages`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name iotedged_eventlog_messages iotedged-eventlog-messages\src\lib.rs --color always --crate-type cdylib --emit=dep-info,link -C opt-level=3 -C metadata=7b3a2d69b8dc278f --out-dir D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps --target thumbv7a-pc-windows-msvc -L dependency=D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\deps -L dependency=D:\git\iotedge\edgelet\target\release\deps -L all=D:\git\iotedge\edgelet\target\thumbv7a-pc-windows-msvc\release\build\iotedged-eventlog-messages-7acc25993b93c4f2\out -l event_messages.res` (exit code: 1)

I did some rough check in the thumbv7a liballoc library, interestingly, the name mangling for EMPTY_ROOT_NODE is different than most of others. The symbol wanted is __imp__ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E, however the one that I have in the thumbv7a lib is __imp___ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E, note there are 2 underscores in the wanted symbol and 3 underscores in the actual symbol. that's because I have this symbol _ZN5alloc11collections5btree4node15EMPTY_ROOT_NODE17h486b4088caeaa846E which already starts with an underscore

Looking at other symbols in the same lib, none of them start with a single underscore, e,g, anon.6bd877021c225a724ec59609200b96d6.6.llvm.13430696783672607638 and __imp__anon.6bd877021c225a724ec59609200b96d6.2.llvm.13430696783672607638.

I have no idea why the toolchain is looking for __imp__ for EMPTY_ROOT_NODE instead of looking for __imp___

Thoughts?

@chandde chandde changed the title unresolved external symbol stdalloc\collections\btree\node\EMPTY_ROOT_NOTE __imp___xxx is found in rust lib, however __imp__xxx is wanted when compiling my rust project May 16, 2019
@alexcrichton
Copy link
Member

I suspect that this block in the compiler may be wrong, if that conditional is updated to check for x86 rather than a 32-bit pointer, perhaps this would be fixed?

@chandde
Copy link
Contributor Author

chandde commented May 16, 2019

I'm now building rustc again, with only the else part "_imp" to try the arm build. I cannot find a variable in the context to check x86 or ARM, suggestions @alexcrichton ?

@alexcrichton
Copy link
Member

I think cgcx.sess().target.target.arch is probably what you want (or something like that)

@chandde
Copy link
Contributor Author

chandde commented May 16, 2019

that particular function does not have CodegenCx which carries session, that function has only CodegenContext. Still looking...

fn create_msvc_imps(
    cgcx: &CodegenContext<LlvmCodegenBackend>,
    llcx: &llvm::Context,
    llmod: &llvm::Module

@chandde
Copy link
Contributor Author

chandde commented May 16, 2019

btw, the private fix using one underscore worked!

@chandde
Copy link
Contributor Author

chandde commented May 16, 2019

I managed to locate a function LLVMGetTarget from llvm which is supposed to return the triple, that I could use to test out x86 vs. arm

pub fn LLVMGetTarget(M: LLVMModuleRef) -> *const ::libc::c_char;

Having some trouble to use this function, it cannot be found in llvm

    let target = llvm::LLVMGetTarget(llmod);
error[E0425]: cannot find function `LLVMGetTarget` in module `llvm`    ] 17/18: rustc_codegen_llvm
   --> src\librustc_codegen_llvm\back\write.rs:801:24
    |
801 |     let target = llvm::LLVMGetTarget(llmod);
    |                        ^^^^^^^^^^^^^ help: a function with a similar name exists: `LLVMGetParam`

error: aborting due to previous error

Not sure if this is an overkill even I make it work eventually, is there an easier/more convenient way of checking the current context is x86 or arm? @alexcrichton

@alexcrichton
Copy link
Member

Ah I see, that's pretty late in the compiler. Currently CodegenContext has a target_pointer_width field and that can probably just be updated to also have a target_arch field and where the field is set you should have access to Session

@chandde
Copy link
Contributor Author

chandde commented May 16, 2019

Thanks! I made necessary changes to include target_arch in codegencontext and it's working well now. I sent PR to rust/master, #60895, please take a look!

@alexcrichton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants