简体   繁体   English

将Linux 32位应用程序移植到64位?

[英]porting linux 32 bit app to 64 bit?

i'm about to port very large scale application to 64 Bits, i've noticed in that in the web there some articles which shows many pitfalls of this porting , i wondered if there is any tool which can assist in porting to 64 bit , meaning finding the places in code that needs to be changed.... maybe the gcc with warnnings enabled... is it good enough ? 我要将非常大规模的应用程序移植到64位,我注意到在网上有一些文章显示了这个移植的许多陷阱,我想知道是否有任何工具可以帮助移植到64位,意味着找到需要更改的代码中的位置....也许启用了警告的gcc ......它是否足够好? is there anything better ? 有更好的吗 ?

EDIT: Guys i am searching for a tool if any that might be a complete to the compiler, i know GCC can asist , but i doubt it will find all un portable problems that 编辑:伙计们我正在寻找一个工具,如果有任何可能是完整的编译器,我知道GCC可以asist,但我怀疑它会找到所有不便携的问题,
will be discovered in run-time....maybe static code analysis tool that emphasize porting to 64 bits ? 将在运行时发现....也许静态代码分析工具,强调移植到64位?

thanks 谢谢

Here 'sa guide. 是一个指南。 Another one 另一个

Size of some data types are different in 32-bit and 64-bit OS, so check for place where the code is assuming the size of data types. 某些数据类型的大小在32位和64位操作系统中是不同的,因此请检查代码假定数据类型大小的位置。 eg If you were casting a pointer to an int, that won't work in 64bit. 例如,如果您正在转换指向int的指针,则无法在64位中运行。 This should fix most of the issues. 这应该解决大多数问题。

If your app uses third-party libraries, make sure those work in 64-bit too. 如果您的应用使用第三方库,请确保它们也能使用64位。

A good tool is called grep ;-) do 一个好工具叫做grep ;-) do

grep -nH -e '\<int\>\|\<short\>\|\<long\>' *

and replace all bare uses of these basic integer types by the proper one: 并用适当的替换所有这些基本整数类型的所有裸使用:

  • array indices should be size_t 数组索引应为size_t
  • pointer casts should be uintptr_t 指针强制转换应该是uintptr_t
  • pointer differences should be prtdiff_t 指针差异应该是prtdiff_t
  • types with an assumption of width N should be uintN_t 假设宽度为N的类型应为uintN_t

and so on, I probably forgot some. 等等,我可能忘记了一些。 Then gcc with all warnings on will tell you. 那么带有所有警告的gcc会告诉你。 You could also use clang as a compiler it gives even more diagnostics. 你也可以使用clang作为编译器,它提供了更多的诊断功能。

First off, why would there be 'porting'? 首先,为什么要“移植”?

Consider that most distros have merrily provided 32 and 64 bit variants for well over a decade . 考虑到大多数发行版在十多年内都快乐地提供了32位和64位变体。 So unless you programmed in truly unportable manner (and you almost have to try) you should be fine. 因此,除非你以真正不可移植的方式编程(而且你几乎要尝试),你应该没问题。

What about compiling the project in 64 bits OS? 在64位操作系统中编译项目怎么样? gcc compiler looks like such tool :) gcc编译器看起来像这样的工具:)

Here is a link to an Oracle webpage that talks about issues commonly encountered porting a 32bit application to 64bit: 以下是Oracle网页的链接,该网页讨论了将32位应用程序移植到64位时常遇到的问题:

http://www.oracle.com/technetwork/server-storage/solaris/ilp32tolp64issues-137107.html http://www.oracle.com/technetwork/server-storage/solaris/ilp32tolp64issues-137107.html

One section talks how to use lint to detect some common errors. 一节讨论如何使用lint检测一些常见错误。 Here is a copy of that section: 这是该部分的副本:

Use the lint Utility to Detect Problems with 64-bit long and Pointer Types Use lint to check code that is written for both the 32-bit and the 64-bit compilation environment. 使用lint实用程序检测64位长和指针类型的问题使用lint检查为32位和64位编译环境编写的代码。 Specify the -errchk=longptr64 option to generate LP64 warnings. 指定-errchk=longptr64选项以生成LP64警告。 Also use the -errchk=longptr64 flag which checks portability to an environment for which the size of long integers and pointers is 64 bits and the size of plain integers is 32 bits. 还可以使用-errchk=longptr64标志来检查对于长整数和指针大小为64位且普通整数大小为32位的环境的可移植性。 The -errchk=longptr64 flag checks assignments of pointer expressions and long integer expressions to plain integers, even when explicit casts are used. -errchk=longptr64标志检查指针表达式和长整数表达式的赋值为纯整数,即使使用显式强制转换也是如此。

Use the -errchk=longptr64,signext option to find code where the normal ISO C value-preserving rules allow the extension of the sign of a signed-integral value in an expression of unsigned-integral type. 使用-errchk=longptr64,signext选项查找代码,其中正常的ISO C值保留规则允许在unsigned-integral类型的表达式中扩展有符号整数值的符号。 Use the -m64 option of lint when you want to check code that you intend to run in the Solaris 64-bit SPARC or x86 64-bit environment. 如果要检查要在Solaris 64位SPARC或x86 64位环境中运行的代码,请使用lint的-m64选项。

When lint generates warnings, it prints the line number of the offending code, a message that describes the problem, and whether or not a pointer is involved. 当lint生成警告时,它会打印违规代码的行号,描述问题的消息以及是否涉及指针。 The warning message also indicates the sizes of the involved data types. 警告消息还指示所涉及数据类型的大小。 When you know a pointer is involved and you know the size of the data types, you can find specific 64-bit problems and avoid the pre-existing problems between 32-bit and smaller types. 当您知道涉及指针并且知道数据类型的大小时,您可以找到特定的64位问题并避免32位和更小类型之间存在的预先存在的问题。

You can suppress the warning for a given line of code by placing a comment of the form "NOTE(LINTED())" on the previous line. 您可以通过在上一行放置“NOTE(LINTED())”形式的注释来禁止给定代码行的警告。 This is useful when you want lint to ignore certain lines of code such as casts and assignments. 当您希望lint忽略某些代码行(如强制转换和赋值)时,这非常有用。 Exercise extreme care when you use the "NOTE(LINTED())" comment because it can mask real problems. 使用“NOTE(LINTED())”注释时要特别小心,因为它可以掩盖实际问题。 When you use NOTE, also include #include. 使用NOTE时,还包括#include。 Refer to the lint man page for more information. 有关更多信息,请参阅lint手册页。

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

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