Skip to content

Assert valid target data string in LLVMCreateTargetData #9370

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

Closed
thielema mannequin opened this issue Jan 18, 2011 · 1 comment
Closed

Assert valid target data string in LLVMCreateTargetData #9370

thielema mannequin opened this issue Jan 18, 2011 · 1 comment
Labels
bugzilla Issues migrated from bugzilla llvm:ir

Comments

@thielema
Copy link
Mannequin

thielema mannequin commented Jan 18, 2011

Bugzilla Link 8998
Version 2.8
OS All
CC @thielema

Extended Description

Please add an assert to LLVMCreateTargetData (i.e. the C++ function that it calls), that checks whether the input string is correct. It seems that there is no way to find out, if an input string is actually valid. If I pass "nonsense" I get a non-NULL pointer as result (that is, the TargetDataRef does not show me, that the input was wrong), and if I pass that to LLVMAddTargetData then things go silently wrong in a very awful way.
See ticket #​6394 for an example.
http://llvm.org/bugs/show_bug.cgi?id=6394

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@JOE1994
Copy link
Member

JOE1994 commented Feb 27, 2024

(checked with llvmorg-17.0.6)

Function LLVMTargetDataRef LLVMCreateTargetData (const char *StringRep) feeds its input string to the following constructor of llvm::DataLayout:

explicit DataLayout(StringRef LayoutDescription) {
  reset(LayoutDescription);
}

DataLayout::reset performs validation checks on input parameter StringRef LayoutDescription, via function DataLayout::parseSpecifier.

void DataLayout::reset(StringRef Desc) {
clear();
LayoutMap = nullptr;
BigEndian = false;
AllocaAddrSpace = 0;
StackNaturalAlign.reset();
ProgramAddrSpace = 0;
DefaultGlobalsAddrSpace = 0;
FunctionPtrAlign.reset();
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
ManglingMode = MM_None;
NonIntegralAddressSpaces.clear();
StructAlignment = LayoutAlignElem::get(Align(1), Align(8), 0);
// Default alignments
for (const auto &[Kind, Layout] : DefaultAlignments) {
if (Error Err = setAlignment(Kind, Layout.ABIAlign, Layout.PrefAlign,
Layout.TypeBitWidth))
return report_fatal_error(std::move(Err));
}
if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64))
return report_fatal_error(std::move(Err));
if (Error Err = parseSpecifier(Desc))
return report_fatal_error(std::move(Err));
}

As there are validation checks in place as requested, I think this ticket can be closed.

@JOE1994 JOE1994 closed this as completed Feb 27, 2024
weliveindetail added a commit to weliveindetail/llvm-project that referenced this issue Nov 5, 2024
weliveindetail added a commit to weliveindetail/llvm-project that referenced this issue Nov 6, 2024
weliveindetail added a commit to weliveindetail/llvm-project that referenced this issue Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:ir
Projects
None yet
Development

No branches or pull requests

2 participants