简体   繁体   English

Arguments 在传入 function 时损坏?

[英]Arguments corrupted on passing in to function?

I'm seeing something that's got me stumped.我看到了让我难过的东西。 Maybe you folks can advise.或许各位大侠可以给点建议。

What appears to be a valid arguments are getting corrupted when passed to a different function.当传递给不同的 function 时,似乎有效的 arguments 会损坏。

Here is my setup:这是我的设置:

  • LibA.a LibA.a
  • LibB.a LibB.a
  • SampleApp示例应用程序
  • MyApp.c MyApp.c

The bad function call is going from LibA in to LibB.坏的 function 调用从 LibA 进入到 LibB。

LibA, LibB and SampleApp have all been pre-complied (thankfully in debug mode) by an older version of Sun Studio on Solaris x86/64. LibA、LibB 和 SampleApp 都已由 Solaris x86/64 上的旧版 Sun Studio 预先编译(幸好处于调试模式)。 SampleApp uses both LibA and LibB and runs just fine on my system. SampleApp 同时使用 LibA 和 LibB 并在我的系统上运行良好。

MyApp uses both LibA and LibB in a manner similar to SampleApp. MyApp 以类似于 SampleApp 的方式使用 LibA 和 LibB。 Yet, MyApp crashes due to this pointer corruption.然而,MyApp 由于指针损坏而崩溃。

// File scoped string declared
static const char myString[] = "SomeText"

// The function call looks like  
libAfunc(myString, myIntVar)

// The called function prototype is like 
int libAfunc(const char* strArg, int intArg)

When single stepping the code, I see the pointer in the caller ( myString ) being valid and being passed as a parameter.单步执行代码时,我看到调用者 ( myString ) 中的指针有效并作为参数传递。 In the callee, the address in the passed-in parameter pointer ( strArg ) is simply wrong.在被调用者中,传入的参数指针( strArg )中的地址完全错误。 In fact, all the parameters are actually wrong after passing in.其实所有参数传入之后其实都是错误的。

Note: The caller is in the pre-compiled LibA and the callee is in the pre-compiled LibB.注意:调用者在预编译的LibA中,被调用者在预编译的LibB中。 I'm never even touching that code since it's all pre-compiled.我什至从未接触过该代码,因为它都是预编译的。 Further, the code itself is probobly correct since SampleApp uses those functions, and runs fine.此外,代码本身可能是正确的,因为 SampleApp 使用了这些函数,并且运行良好。 (Although the call sequence could be slightly different...) (虽然调用顺序可能略有不同......)

I'm thinking that my error is in the linking stage, but I'm not sure what it could be.我在想我的错误是在链接阶段,但我不确定它可能是什么。

Any ideas?有任何想法吗?

Thank you谢谢

Can you compile SimpleApp with your compiler?你能用你的编译器编译 SimpleApp 吗? Does it still work?它仍然有效吗?

I'm not familiar with your particular platform, but there was a time with some compilers where pointers could be different sizes depending upon the compiler options used.我不熟悉您的特定平台,但曾经有一段时间使用某些编译器,其中指针的大小可能不同,具体取决于所使用的编译器选项。

If your compiler was producing (say) 64 bit pointers and the libs were using 32 bit pointers then your symptoms make sense.如果您的编译器正在生成(例如)64 位指针并且库使用 32 位指针,那么您的症状是有道理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM