【问题标题】:Does Clang have an equivalent to GCC's -malign-double flag?Clang 是否与 GCC 的 -malign-double 标志等效?
【发布时间】:2012-04-22 20:12:31
【问题描述】:

似乎 -malign-double 编译器选项已从 Clang 中删除。示例代码:

#include <stddef.h>
#include <stdio.h>

typedef struct X { char a; long long b; } X;

int main(void)
{
  printf("%zd\n", offsetof(X, b));
  return 0;
}

当在 32 位模式 (-m32) 下使用 GCC 编译时,这可以输出 8 或 4,具体取决于是否分别启用了 -malign-double。但 Clang 似乎不支持此选项:

$ clang test.c -m32 -malign-double
clang: warning: argument unused during compilation: '-malign-double'
$ ./a.out
4

Clang 版本:

Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix

我似乎在 Clang 支持的编译器标志的完整列表中找不到任何官方文档,它们似乎大部分都遵循 GCC 的文档。

Clang 中是否有与-malign-double 等效的电流?还是我现在不得不使用不同的编译器?我需要它来编译一些链接到使用该标志的纯二进制第三方库的代码。

【问题讨论】:

  • 你得到答案了吗?
  • 好吧,看起来这仍然不可能,正如有人在 irc 上告诉我的那样:“ 如果可能的话(例如不受 ABI 限制),LLVM 将使用自然对齐 | 如果是生成代码,总是可以使用属性强制对齐"

标签: gcc clang compiler-flags


【解决方案1】:

这似乎现在已修复:

commit 3205dbb3f1f96e77e106f964dcf1b5f69fba4ecc
Author: Craig Topper <craig.topper@intel.com>
Date:   Thu Mar 21 20:07:24 2019 +0000

    [Driver] Pass -malign-double from the driver to the cc1 command line

    -malign-double is currently only implemented in the -cc1 interface.
    But its declared in Options.td so it is a driver option too.
    But you try to use it with the driver you'll get a message about the
    option being unused.

    This patch teaches the driver to pass the option through to cc1 so it won't
    be unused. The Options.td says the option is x86 only but I didn't see any
    x86 specific code in its implementation in cc1 so not sure if the
    documentation is wrong or if I should only pass this option through the
    driver on x86 targets.

    Differential Revision: https://reviews.llvm.org/D59624

    llvm-svn: 356706

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多